- Create
.envfile from.env.sampleand update the relevant variables.
# Move to 'workshop-2' directory
cd workshop-2
# Export the environment variables to the shell
export $(grep -v '^#' .env | xargs)# Deploy Cognito Services with CDK
cdk deploy --profile ${AWS_USERNAME}- Install source dependencies.
pip install -r src/requirements.txt -t src/packages/python- Set
STACK_BOOK_ENABLEDin.envtotruethen export the variables to the terminal again.
# Export the environment variables to the shell
export $(grep -v '^#' .env | xargs)Before start, we need to have a CloudWatch Logs roles configured for API Gateway logging.
- Create CloudWatch Logs role (if it does not exist):
# Create role
aws iam create-role --role-name APIGatewayCloudWatchLogsRole --assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "apigateway.amazonaws.com" },
"Action": "sts:AssumeRole"
}]
}'
# Attach role to this role
aws iam attach-role-policy --role-name APIGatewayCloudWatchLogsRole --policy-arn arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs
# Find the ARN for the role
aws iam get-role --role-name APIGatewayCloudWatchLogsRole --query 'Role.Arn' --output text
# Set the CloudWatch Logs role ARN for API Gateway
# Replace <ROLE_ARN> with ARN you got in previous step
aws apigateway update-account --patch-operations op=replace,path=/cloudwatchRoleArn,value=<ROLE_ARN>- Then deploy the cdk stack again using
cdk deploy. You can also runcdk synthbefore the deployment and have a look oncdk.outfolder to see the changes in the stack.
# Deploy Book Service with CDK
cdk deploy --profile ${AWS_USERNAME}- Replace
<AWS_USERNAME>with your AWS Username in src/seeders/data-seeder.json (line 2).
{
"<AWS_USERNAME>Books":[ // => Replace <AWS_USERNAME> with your AWS Username (For example: sd0001)
...
]
}- Run Data Seeder for DynamoDB Books Table
aws dynamodb batch-write-item --profile ${AWS_USERNAME} --request-items file://./src/seeders/data-seeder.json- Set
STACK_BOOK_REVIEW_ENABLEDin.envtotruethen export the variables to the terminal again.
# Export the environment variables to the shell
export $(grep -v '^#' .env | xargs)- Then deploy the cdk stack again using
cdk deploy.
# Deploy Book Services with CDK
cdk deploy --profile ${AWS_USERNAME}# Destroy All Stacks
cdk destroy --profile ${AWS_USERNAME}

