Last active
May 19, 2020 11:11
-
-
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! π
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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