
Q-Bits: Automating CDK with Amazon Q Developer Customizations
By taking the time to customize Amazon Q Developer, I've been able to streamline my CDK development.
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with Automating CDK Best Practices.
CustomInstance
construct automatically selects the appropriate Amazon Elastic Compute Cloud (Amazon EC2) AMI and Amazon Virtual Private Cloud (Amazon VPC) based on a property called environment. This simplifies the configuration for the developers and ensures consistent deployments. 1
2
3
4
5
6
const instance = new CustomInstance(this, 'WebServer', {
name: 'web-server-01',
environment: 'Testing',
operatingSystem: 'Windows',
...
});
CustomBucket
construct enforces our security best practices for Amazon Simple Storage Service (Amazon S3). I have overridden some properties such as blocking public access, enabling bucket encryption, and enforcing TLS. This ensure that the developers follow our standards. 1
2
3
4
5
6
const bucket = new CustomBucket(this, 'MyBucket', {
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
encryption: s3.BucketEncryption.S3_MANAGED,
enforceSSL: true,
...
});
1
2
3
4
5
6
7
8
9
10
// Create a Linux production server named web001
new cdk.aws_ec2.Instance(this, 'web001', {
vpc: cdk.aws_ec2.Vpc.fromLookup(this, 'vpc', { isDefault: true }),
instanceType: new cdk.aws_ec2.InstanceType('t3.micro'),
machineImage: cdk.aws_ec2.MachineImage.latestAmazonLinux({
generation: cdk.aws_ec2.AmazonLinuxGeneration.AMAZON_LINUX_2,
}),
allowAllOutbound: true,
instanceName: 'web001',
});
custom-construct
module. In the following example, Q realizes that I want to use a custom construct, but it knows nothing about my constructs. 1
2
3
4
5
6
7
8
9
10
11
12
import * as myconstructs from 'custom-constructs';
...
// Create a Linux production server named web001
new myconstructs.ProductionServer(this, 'web001', {
amiName: 'amzn2-ami-kernel-5.10-hvm-2.0*', // Amazon Linux 2 AMI
instanceType: 't2.micro',
keyName: 'my-key-pair',
tags: [{ Key: 'Name', Value: 'web001' }],
vpcId: 'XXXXXXXXXXXX'
});
CustomInstance
construct and the correct properties. 1
2
3
4
5
6
7
8
9
10
import * as myconstructs from 'custom-constructs';
...
// Create a Linux production server named web001
new myconstructs.CustomInstance(this, 'MyInstance', {
name: 'web001',
environment: 'Production',
operatingSystem: 'Linux',
});
custom-constructs
module. So Q will recommend my custom constructs even if a new developer forgets to include the module. 1
2
3
4
5
6
// Create a Linux production server named web001
new myconstructs.CustomInstance(this, 'MyInstance', {
name: 'web001',
environment: 'Production',
operatingSystem: 'Linux',
});
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.