CloudWatch Logs
- 1. TerraConstructs - AWS Intro Workshop: not reached
- 2. Prerequisites: not reached
- 3. AWS CLI: not reached
- 4. AWS Account and User: not reached
- 5. Node.js: not reached
- 6. IDE for your programming language: not reached
- 7. CDKTN CLI Toolkit: not reached
- 8. Terraform CLI: not reached
- 9. TypeScript Workshop: not reached
- 10. New Project: not reached
- 11. CDKTN init: not reached
- 12. Project structure: not reached
- 13. TerraConstructs: not reached
- 14. CDKTN synth: not reached
- 15. CDKTN deploy: not reached
- 16. Hello, CDKTN!: not reached
- 17. Cleanup sample: not reached
- 18. Hello Lambda: not reached
- 19. Optional - Watch: not reached
- 20. API Gateway: not reached
- 21. Writing constructs: not reached
- 22. Define the HitCounter API: not reached
- 23. Hit counter handler: not reached
- 24. Define resources: not reached
- 25. Use the hit counter: not reached
- 26. CloudWatch Logs: not reached (this page)
- 27. Granting permissions: not reached
- 28. Test the hit counter: not reached
- 29. Using construct libraries: not reached
- 30. Learning about the Table Viewer construct: not reached
- 31. Installing the library: not reached
- 32. Add the table viewer to your app: not reached
- 33. Exposing our hit counter table: not reached
- 34. Deploying our app: not reached
- 35. Extra credit: not reached
- 36. Clean up: not reached
- 37. Advanced Topics: not reached
- 38. Testing Constructs: not reached
- 39. Assertion Tests: not reached
- 40. Congrats!: not reached
Viewing CloudWatch logs for our Lambda function
The first thing to do is to go and look at the logs of our hit counter AWS Lambda function.
There are many tools that help you do that like SAM CLI and awslogs. In this workshop, we'll show you how to find your logs through the AWS console.
-
Open the AWS Lambda console (make sure you are connected to the correct region).
-
Click on the HitCounter Lambda function (the name should contain the string
cdk-workshop-dev-...HitCounterHandler):
-
Click on Monitoring

-
Click on View Logs in CloudWatch. This will open the AWS CloudWatch console.

-
Select the most-recent log group.
-
Look for the most-recent message containing the string "errorMessage". You'll likely see something like this:
You can also stream the recent log entries from the terminal:
aws logs tail /aws/lambda/<hit-counter-function-name> --since 10m --format short{ "errorType": "AccessDeniedException", "errorMessage": "User: arn:aws:sts::694710432912:assumed-role/cdk-workshop-dev-cdrHandlerServiceRole20250715042121401600000001/cdk-workshop-dev-cderHitCounterHandler is not authorized to perform: dynamodb:UpdateItem on resource: arn:aws:dynamodb:us-east-1:694710432912:table/cdkworkshopHelloHitCounterHitsF0859462 because no identity-based policy allows the dynamodb:UpdateItem action", "name": "AccessDeniedException", "stack": [ "AccessDeniedException: User: arn:aws:sts::694710432912:assumed-role/cdk-workshop-dev-cdrHandlerServiceRole20250715042121401600000001/cdk-workshop-dev-cderHitCounterHandler is not authorized to perform: dynamodb:UpdateItem on resource: arn:aws:dynamodb:us-east-1:694710432912:table/cdkworkshopHelloHitCounterHitsF0859462 because no identity-based policy allows the dynamodb:UpdateItem action", " at throwDefaultError (/var/runtime/node_modules/@aws-sdk/node_modules/@smithy/smithy-client/dist-cjs/index.js:867:20)", " at /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/smithy-client/dist-cjs/index.js:876:5", " at de_CommandError (/var/runtime/node_modules/@aws-sdk/client-dynamodb/dist-cjs/index.js:2297:14)", " at process.processTicksAndRejections (node:internal/process/task_queues:105:5)", " at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-serde/dist-cjs/index.js:35:20", " at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/core/dist-cjs/index.js:193:18", " at async /var/runtime/node_modules/@aws-sdk/node_modules/@smithy/middleware-retry/dist-cjs/index.js:320:38", " at async /var/runtime/node_modules/@aws-sdk/middleware-logger/dist-cjs/index.js:33:22", " at async exports.handler (/var/task/hitcounter.js:12:3)" ] }
It seems like our Lambda function can't write to our DynamoDB table. This actually makes sense - we didn't grant it those permissions! Let's go do that now.
Forcing a redeployment
To force a redeployment through terraform we use apply with -replace
flag (docs),
but first we need to know the logical address for the deployment.
-
Go to the stack directory
cd cdktf.out/stacks/cdk-workshop -
Grep the state for the deployment resource
terraform state list | grep deploymentYou should see something like:
aws_api_gateway_deployment.Endpoint_Deployment_318525DA -
Force the deployment to be re-created
terraform apply -replace aws_api_gateway_deployment.Endpoint_Deployment_318525DA
Now confirm the deployment history on the prod stage:
-
Open the AWS Api Gateway console (make sure you are connected to the correct region).
-
Click on the cdkworkshopEndpoint API

-
Review the Stages deployment history

You can also list the deployment history for the API ID shown in the
cdktn deployoutput:aws apigateway get-deployments --rest-api-id <rest-api-id>