Repository navigation
Expand file tree
/
Copy pathprepare.sh
More file actions
executable file
·45 lines (36 loc) · 1.85 KB
/
Copy pathprepare.sh
File metadata and controls
executable file
·45 lines (36 loc) · 1.85 KB
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
#!/bin/bash
export TABLE_NAME="votingapp-restaurants"
export IAM_ROLE="votingapp-role"
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query 'Account')
export AWS_REGION=$(aws configure get region)
if [ -z ${AWS_REGION} ]; then echo "you need to export the AWS_REGION variable"; exit; fi
aws dynamodb create-table \
--table-name $TABLE_NAME \
--attribute-definitions AttributeName=name,AttributeType=S \
--key-schema AttributeName=name,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--region $AWS_REGION
echo "waiting a few seconds for the table to be available"
sleep 10
aws dynamodb put-item \
--table-name $TABLE_NAME \
--item '{"name": {"S": "ihop"}, "restaurantcount": {"N": "0"}}' \
--region $AWS_REGION
aws dynamodb put-item \
--table-name $TABLE_NAME \
--item '{"name": {"S": "outback"}, "restaurantcount": {"N": "0"}}' \
--region $AWS_REGION
aws dynamodb put-item \
--table-name $TABLE_NAME \
--item '{"name": {"S": "bucadibeppo"}, "restaurantcount": {"N": "0"}}' \
--region $AWS_REGION
aws dynamodb put-item \
--table-name $TABLE_NAME \
--item '{"name": {"S": "chipotle"}, "restaurantcount": {"N": "0"}}' \
--region $AWS_REGION
aws iam create-role --role-name $IAM_ROLE --assume-role-policy-document file://apprunner-trust-policy.json
sed -e "s@ACCOUNT_ID@$ACCOUNT_ID@g" -e "s@AWS_REGION@$AWS_REGION@g" -e "s@TABLE_NAME@$TABLE_NAME@g" votingapp-ddb-policy.json > filled-votingapp-ddb-policy.json
aws iam create-policy --policy-name votingapp-ddb-policy --policy-document file://./filled-votingapp-ddb-policy.json
rm filled-votingapp-ddb-policy.json
aws iam attach-role-policy --role-name $IAM_ROLE --policy-arn arn:aws:iam::$ACCOUNT_ID:policy/votingapp-ddb-policy
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess --role-name $IAM_ROLE