This repository has been archived by the owner on May 7, 2020. It is now read-only.
forked from Pizzaface/Alexa-Chromecast-Skill-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws-setup.sh
executable file
·55 lines (47 loc) · 2.28 KB
/
aws-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash -e
source ./config/variables
if [ -z "$(type aws)" ]; then
echo "Installing AWS CLI tools."
pip install awscli
if -z "$(type aws)"; then
echo "aws is not in path.. please check and re-run."
exit 1
else
echo "Done."
echo "Running 'aws configure'"
aws configure
fi
fi
rm -f .env
# Create Role
echo "Creating $ROLE_NAME role."
role_response=$(aws iam create-role --role-name $ROLE_NAME --assume-role-policy-document file://$(pwd)/config/aws-lambda-role-policy.json)
role_arn=$(echo $role_response | python -c "import sys, json; print(json.load(sys.stdin)['Role']['Arn'])")
aws iam attach-role-policy --role-name $ROLE_NAME --policy-arn arn:aws:iam::aws:policy/AmazonSNSFullAccess
# Create SNS Topic (and store ARN in .env)
echo "Creating $SNS_TOPIC_NAME topic."
sns_response=$(aws sns create-topic --name $SNS_TOPIC_NAME)
sns_topic_arn=$(echo $sns_response | python -c "import sys, json; print(json.load(sys.stdin)['TopicArn'])")
echo "export AWS_SNS_TOPIC_ARN=$sns_topic_arn" >> .env
# Create Lambda function (and store ARN in .env)
echo "Creating $LAMBDA_FUNCTION_NAME lambda function."
./build-lambda-bundle.sh
lambda_response=$(aws lambda create-function --function-name $LAMBDA_FUNCTION_NAME --runtime "python2.7" --handler "main.lambda_handler" --role $role_arn --zip-file fileb://lambda-build.zip)
lambda_arn=$(echo $lambda_response | python -c "import sys, json; print(json.load(sys.stdin)['FunctionArn'])")
echo "export LAMBDA_FUNCTION_ARN=$lambda_arn" >> .env
aws lambda update-function-configuration --function-name $LAMBDA_FUNCTION_NAME --environment "Variables={AWS_SNS_ARN=$sns_topic_arn}"
aws lambda add-permission --function-name $LAMBDA_FUNCTION_NAME --statement-id 1 --action lambda:invokeFunction --principal alexa-appkit.amazon.com
# Get user input for the chromecast name (and store the name in .env)
echo -n 'Enter your your chromecast'\''s name (Default="Living Room"): '
read chromecastName
if [ "$chromecastName" = "" ]; then
chromecastName="Living Room"
fi
echo "export CHROMECAST_NAME=\"$chromecastName\"" >> .env
echo "Done!"
echo
echo "Next, go to https://developer.amazon.com/edw/home.html#/skills/list and create an Alexa Skill."
echo "Lambda function ARN: $lambda_arn"
echo
echo "Then run the local handler."
echo "SNS Topic ARN: $sns_topic_arn"