Skip to content

Latest commit

 

History

History
100 lines (80 loc) · 2.89 KB

File metadata and controls

100 lines (80 loc) · 2.89 KB

Module 1 - Book Service

alt Workshop 2 - Module 1

Cognito Service

  • Create .env file from .env.sample and 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}

Book API Service

Part 1: Book Resource Endpoint

alt Module 1 - Part 1

  • Install source dependencies.
pip install -r src/requirements.txt -t src/packages/python
  • Set STACK_BOOK_ENABLED in .env to true then 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 run cdk synth before the deployment and have a look on cdk.out folder to see the changes in the stack.
# Deploy Book Service with CDK
cdk deploy --profile ${AWS_USERNAME}
{
    "<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

Part 2: Book Review Resource Endpoints

alt Module 1 - Part 1

  • Set STACK_BOOK_REVIEW_ENABLED in .env to true then 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}

Clean Up All Stacks

# Destroy All Stacks
cdk destroy --profile ${AWS_USERNAME}