Created
August 5, 2019 04:30
-
-
Save alevz257/69dd688e5c83be070a9dc393ded5077d to your computer and use it in GitHub Desktop.
AWS CDK - using javascript
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
const cdk = require('@aws-cdk/core'); | |
const ec2 = require('@aws-cdk/aws-ec2'); | |
const ecs = require('@aws-cdk/aws-ecs'); | |
const ecs_patterns = require ('@aws-cdk/aws-ecs-patterns'); | |
class Cdk1Stack extends cdk.Stack { | |
constructor(scope, id, props) { | |
super(scope, id, props); | |
// The code that defines your stack goes here | |
//create vpc | |
this.vpc = new ec2.Vpc(this, 'vpc', { | |
maxAZs: 2, | |
natGateways: 1 | |
}); | |
//create ECS cluster | |
this.cluster = new ecs.Cluster(this, 'ecsCluster',{ | |
vpc: this.vpc | |
}); | |
//add instances t2.micro for free tier | |
this.cluster.addCapacity('DefaultAutoScalingGroup', { | |
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T2, ec2.InstanceSize.MICRO) | |
}); | |
//add container by using ecs_pattern | |
this.ecsServicePHP = new ecs_patterns.LoadBalancedEc2Service(this, 'ecsEc2ServicePHP', { | |
cluster: this.cluster, | |
memoryLimitMiB: 400, | |
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample") | |
}); | |
} | |
} | |
module.exports = { Cdk1Stack } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment