Skip to content

Instantly share code, notes, and snippets.

@markusl
Created August 8, 2019 09:26
Show Gist options
  • Save markusl/9cbaf7cfc8088e2ba7ca79eb65910bb8 to your computer and use it in GitHub Desktop.
Save markusl/9cbaf7cfc8088e2ba7ca79eb65910bb8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
import 'source-map-support/register';
import * as core from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecs_patterns from '@aws-cdk/aws-ecs-patterns';
// Example code from: https://docs.aws.amazon.com/cdk/latest/guide/home.html
export class MyEcsConstructStack extends core.Stack {
constructor(scope: core.App, id: string, props?: core.StackProps) {
super(scope, id, props);
const vpc = new ec2.Vpc(this, "MyVpc", {
maxAzs: 3 // Default is all AZs in region
});
const cluster = new ecs.Cluster(this, "MyCluster", {
vpc: vpc
});
// Create a load-balanced Fargate service and make it public
new ecs_patterns.LoadBalancedFargateService(this, "MyFargateService", {
cluster: cluster, // Required
cpu: 512, // Default is 256
desiredCount: 6, // Default is 1
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"), // Required
memoryLimitMiB: 2048, // Default is 512
publicLoadBalancer: true // Default is false
});
}
}
const myApp = new core.App();
new MyEcsConstructStack(myApp, 'FargateExampleStack', { });
myApp.synth();
{
"name": "aws-cdk-example",
"version": "0.1.0",
"bin": {
"aws-cdk-example": "bin/aws-cdk-example.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"cdk": "cdk"
},
"devDependencies": {
"@types/node": "12.6.8",
"@aws-cdk/aws-ec2": "^1.3.0",
"@aws-cdk/aws-ecs": "^1.3.0",
"@aws-cdk/aws-ecs-patterns": "^1.3.0",
"@aws-cdk/aws-s3": "^1.3.0",
"source-map-support": "^0.5.13",
"typescript": "^3.5.3",
"ts-node": "^8.3.0",
"aws-cdk": "^1.3.0"
},
"dependencies": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment