Last active
February 16, 2020 18:41
-
-
Save cagdas1/3c1449df10d9cd7131e0473308fae66c to your computer and use it in GitHub Desktop.
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 ec2 from "@aws-cdk/aws-ec2"; | |
import * as cdk from '@aws-cdk/core'; | |
export class MyEc2AppStack extends cdk.Stack { | |
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
// Create new VPC | |
const vpc = new ec2.Vpc(this, 'VPC'); | |
// Open port 22 for SSH connection from anywhere | |
const mySecurityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', { | |
vpc, | |
securityGroupName: "my-test-sg", | |
description: 'Allow ssh access to ec2 instances from anywhere', | |
allowAllOutbound: true | |
}); | |
mySecurityGroup.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(22), 'allow public ssh access') | |
// We are using the latest AMAZON LINUX AMI | |
const awsAMI = new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AMAZON_LINUX_2 }); | |
// Instance details | |
const ec2Instance = new ec2.Instance(this, 'Instance', { | |
vpc, | |
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.NANO), | |
machineImage: awsAMI, | |
securityGroup: mySecurityGroup | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment