The slides are available in the Slides folder
- Go to
exercises/cdk. - Insert your AWS Account ID in
exercises/cdk/bin/app.ts - Set your configuration (Linux/Mac: Use
export AUTHOR=...)
set AUTHOR=<Insert your user>
set AWS_PROFILE=cdk-workshop
set AWS_REGION=eu-west-1
- Deploy to AWS
npm run cdk deploy. - (After exercise 1A) The deployment command should print the URL of the deployed webpage as a Cloudformation output.
- Goals: First deployment (a DynamoDB table) and getting started with the CDK.
- Go to
exercises/cdkand make yourself familiar with the code. - run
npm run cdk synth, contemplate the generated template in the cdk.out folder andnpm run cdk deploy.
- Goals:
- Deploy our example application, which serves a static web page.
- Access the web page in your browser.
- Use a cdk pattern to deploy a Fargate service behind a loadbalancer.
- Use an existing ECS cluster.
- Starting point: Go to
exercises/cdk/lib/simple-fargate-service-stack.ts - We already deployed a shared stack called
cdk-workshop-shared-resources, which defines a vpc, ECS cluster. Import these into your stack. - Visit the URL printed as an output in the deploy command.
- Go to the
exercises/service/directory and run./gradlew dockerBuildImage - Adapt the code in
exercises/cdk/lib/simple-fargate-service-stack.ts - Validate your changes by running cdk diff and deploy your service.
Set the DesiredTaskCount of our Service to 2.
Add Auto-Scaling to the Service. When the service uses more than 5% of its memory, it should use 3 instances. Hint: Investigate the 'service' property of your ApplicationLoadBalancedFargateService.
Make the size of the CPU and the memory of the task definition depending on the AWS region you are deploying into (not all combinations of CPU and memory values are valid, check Docu). We have deployed the shared-resources-stack into eu-west-1 and eu-central-1.
Write a test that verifies the code from 3A by inspecting the Cloudformation template.
- Starting point:
exercises/cdk/test/simple-fargate-service.test.ts
Write a test that ensures that logs in every log group of the stack are discarded after at most one week. Ideally your test code should not depend on the concrete resources created in the stack. Afterwards make the test green by specifying the retention time of the log-group of our service or by solving exercise 3D.
- Starting point:
exercises/cdk/test/simple-fargate-service.test.ts
Write an aspect that automatically limits the retention time for all log groups in scope in order to make the test of 3C green.
Goal: When you open the webpage deployed by our service, the visitor should be saved in the database 'visitors-${AUTHOR}' added in Exercise 0. Additionally, all visitors should be listed on the webpage. Our source code already contains the logic and performs a PUT and SCAN.
Give the service general read and write permissions to the database.
- Starting point:
exercises/cdk/lib/simple-fargate-service-stack.ts - Pass the table name as an environment variable TABLE_NAME to the service
- Make the table grant the task role read and write permissions
Inspect the resulting policy/role from 4A with cdk synth and restrict the permissions to only the necessary ones.
After cd cdk:
npm run cdk deploydeploy this stack to your default AWS account/region (Dockerfile needs to be created before)npm run cdk diffcompare deployed stack with current statenpm run cdk synthemits the synthesized CloudFormation template
./gradlew dockerCreateDockerfilecreate Dockerfile to package application./gradlew dockerBuildImagepackage the application as Docker image