Skip to content

Instantly share code, notes, and snippets.

@vtj-ttanaka
Created April 24, 2024 11:08
Show Gist options
  • Save vtj-ttanaka/9a77f5ef449c56fb2ebdfea3e551e595 to your computer and use it in GitHub Desktop.
Save vtj-ttanaka/9a77f5ef449c56fb2ebdfea3e551e595 to your computer and use it in GitHub Desktop.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
export class CdkStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, 'vpc', {
vpcId: 'vpc-12345678901234567'
});
const instance = new ec2.Instance(this, 'ec2', {
vpc: vpc,
vpcSubnets: {
subnets: [
ec2.Subnet.fromSubnetAttributes(this, 'subnet-1', {
subnetId: 'subnet-12345678901234567',
availabilityZone: 'ap-northeast-1a',
}),
]
},
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
machineImage: new ec2.AmazonLinuxImage({
generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023,
}),
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment