/alexa-aws-instance

Manipulate an AWS EC2 instance using Amazon Alexa

Primary LanguageJavaScriptMIT LicenseMIT

alexa-aws-instance

Manipulate an AWS EC2 instance using Amazon Alexa. You can use this skill to control a named EC2 instance in your AWS account - start, stop, check status and find the public IP and ask how long it has been up for.

Pre-requisites

Installation

  1. Clone the repository.

    $ git clone https://github.com/charltones/alexa-aws-instance.git
  2. Initialize the ASK CLI by Navigating into the repository and running npm command: ask init. Follow the prompts.

    $ cd skill-sample-nodejs-howto
    $ ask init
  3. Install npm dependencies by navigating into the /lambda/custom directory and running the npm command: npm install

    $ cd lambda/custom
    $ npm install

Deployment

ASK CLI will create the skill and the lambda function for you. The Lambda function will be created in us-east-1 (Northern Virginia) by default.

  1. Deploy the skill and the lambda function in one step by running the following command:

    $ ask deploy
  2. Amend the role used for the Lambda function in the AWS management console to allow it access to EC2. This will let it call describe instances, stop instances and start instances. Create the following as a new policy and attach the policy to the role that Alexa Skills Kit creates for you:

    {
    	"Version": "2012-10-17",
    	"Statement": [
    		{
    			"Sid": "sid0",
    			"Effect": "Allow",
    			"Action": [
             		"ec2:DescribeInstances",
    				"ec2:StartInstances",
    				"ec2:StopInstances"
    			],
    			"Resource": "*"
    		}
    	]
    }
    

Usage

Once the skill is deployed, you can test it from the command line or via the Alexa skills page here. After testing, you can use it with your own Alexa devices, just say:

ask my instance is {name} running
ask my instance how long has {name} been on for
ask my instance what is the address for {name}
ask my instance switch on {name}
ask my instance shut down {name}

Currently this will search EC2 instances in the eu-west-1 region only, looking for instances which match the Name tag with the name specified. It tries to match name against a person's first name (specified in the en-GB.json file as AMAZON.GB_FIRST_NAME). You can change the code to match other sets of strings according to the slot type reference here.