Skip to content

Instantly share code, notes, and snippets.

@darko-mesaros
Last active May 19, 2020 11:11
Show Gist options
  • Save darko-mesaros/928628c0b0a524899968fd9bcfd2cc22 to your computer and use it in GitHub Desktop.
Save darko-mesaros/928628c0b0a524899968fd9bcfd2cc22 to your computer and use it in GitHub Desktop.
Launch an EC2 instance with CDK, by using the latest Amazon Linux AMI - Powered by SSM Parameter store! πŸ”
import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
export class CdkSsmEc2Stack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// import the default VPC
const vpc = ec2.Vpc.fromLookup(this, 'VPC', {
isDefault: true,
});
// launch new EC2 instance with the latest AMI
const myInstance = new ec2.Instance(this, 'MyInstance',{
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
machineImage: new ec2.AmazonLinuxImage(),
vpc: vpc
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment