AWS CDK - Writing and Sharing Constructs

This is Chapter 3 of the Infrastructure as Code with AWS CDK series. Chapters 1 and 2 put the S3 bucket and Lambda directly in MyStack. Both get extracted into a reusable construct here. L1, L2, L3 CDK organises constructs into three levels: L1 - raw CloudFormation resource wrappers, prefixed with Cfn. CfnBucket, CfnFunction. No defaults added - every property must be set explicitly. L2 - CDK’s built-in higher-level constructs. s3.Bucket, _lambda.Function. These set sensible defaults, expose helper methods, and handle IAM via grant_* methods. L3 - composite constructs you write that bundle multiple resources into a single unit. The previous chapters used L2 constructs directly inside a stack. This chapter builds an L3. The problem The current MyStack creates the bucket and Lambda directly: ...

May 14, 2025 · 3 min · 558 words

AWS CDK - Managing Configuration and Context

This is Chapter 2 of the Infrastructure as Code with AWS CDK series. Four approaches to environment-specific configuration in CDK stacks - same use case throughout so the trade-offs sit side by side. Use case: An S3 bucket and Lambda function where bucket name, log level, and Lambda timeout vary per environment (dev, staging, prod). Quick comparison Approach Version controlled Supports secrets Change without redeploy Shared across stacks Static config (cdk.json) Yes No No No Dynamic config No Partial Yes No Secrets Manager No Yes Yes Yes CI/CD context injection No No Yes No Local dev patterns Suitable for personal projects or local development. Neither is a good fit for CI/CD pipelines or shared team environments. ...

April 28, 2025 · 5 min · 882 words

AWS CDK - Project Setup and Bootstrapping

This is Chapter 1 of the Infrastructure as Code with AWS CDK series. Two things come before writing any stack code: initialising the CDK project and bootstrapping the AWS account. Prerequisites Python 3.9+ Node.js 18+ (CDK CLI is a Node package) AWS CLI v2 configured with valid credentials - see Connecting to AWS SSO and SSH into EC2 Instance An AWS account with permissions to create IAM roles, S3 buckets, and CloudFormation stacks Install the CDK CLI globally: ...

March 11, 2025 · 3 min · 491 words

Installing CloudWatch Agent in EC2 Instance

EC2 does not send memory or disk metrics to CloudWatch by default - only CPU, network and status checks. The CloudWatch agent runs inside the instance and collects system-level metrics and logs directly. Prerequisites EC2 instance running (Amazon Linux 2 or Ubuntu) SSH access to the instance - see Connecting to AWS SSO and SSH into EC2 Instance Terminal Attach IAM role to the instance The agent needs permission to write metrics and logs to CloudWatch. In the AWS console: ...

December 3, 2024 · 2 min · 356 words

AWS Certified Cloud Practitioner (CLF-C02) Study Notes

I sat the AWS Certified Cloud Practitioner (CLF-C02) back in 2024 and passed. CLF-C02 is AWS’s foundational certification - broad rather than deep, covering cloud concepts, security, core services, and billing at a level anyone working around AWS should recognise. It is the most accessible AWS exam, so if you already work with AWS day to day, a lot of this will be familiar. Treat it as a breadth check rather than a deep technical exam, and calibrate the prep to what you already know. ...

November 15, 2024 · 6 min · 1142 words