Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// VPC
const vpc = new Vpc(this, "Vpc", {
cidr: "10.0.0.0/16",
natGateways: 0,
subnetConfiguration: [
{ name: "aasa_isolated", subnetType: SubnetType.ISOLATED }
]
});
const subnetIds: string[] = [];
vpc.isolatedSubnets.forEach(subnet => {
subnetIds.push(subnet.subnetId);
});
// SUBNET GROUP
const dbSubnetGroup: CfnDBSubnetGroup = new CfnDBSubnetGroup(
this,
"AuroraSubnetGroup",
constructor(scope, id, props) {
super(scope, id, props);
// Load config file
var config = yaml.safeLoad(fs.readFileSync('./s3_bucket_files/cdk_app.yaml', 'utf8'));
if (config['s3_bucket'] == 'MYCOMPANY-cloudmapper') {
console.log("You must configure the CDK app by editing ./s3_bucket_files/cdk_app.yaml");
process.exit(1);
}
// Create VPC to run everything in. We make this public just because we don't
// want to spend $30/mo on a NAT gateway.
const vpc = new ec2.Vpc(this, 'CloudMapperVpc', {
maxAzs: 1,
natGateways: 0,
subnetConfiguration: [
{
name: 'Public',
subnetType: ec2.SubnetType.PUBLIC
}
]
});
// Define the ECS task
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
const taskDefinition = new ecs.FargateTaskDefinition(this, 'taskDefinition', {});
taskDefinition.addContainer('cloudmapper-container', {
constructor(scope: cdk.Construct, id: string, props: LoadBalancedFargateServiceAppletProps) {
super(scope, id, props);
const vpc = new Vpc(this, 'MyVpc', { maxAZs: 2 });
const cluster = new Cluster(this, 'Cluster', { vpc });
let domainZone;
if (props.domainZone) {
domainZone = new HostedZoneProvider(this, { domainName: props.domainZone }).findAndImport(this, 'Zone');
}
let certificate;
if (props.certificate) {
certificate = Certificate.fromCertificateArn(this, 'Cert', props.certificate);
}
// Instantiate Fargate Service with just cluster and image
new LoadBalancedFargateService(this, "FargateService", {
cluster,
cpu: props.cpu,
containerPort: props.containerPort,
constructor(parent: cdk.App, name: string, props: TriviaBackendStackProps) {
super(parent, name, props);
// Network infrastructure
const vpc = new Vpc(this, 'VPC', { maxAzs: 2 });
const serviceSG = new SecurityGroup(this, 'ServiceSecurityGroup', { vpc });
// Lookup pre-existing TLS certificate
const certificateArn = StringParameter.fromStringParameterAttributes(this, 'CertArnParameter', {
parameterName: 'CertificateArn-' + props.domainName
}).stringValue;
// Load balancer
const loadBalancer = new ApplicationLoadBalancer(this, 'ServiceLB', {
vpc,
internetFacing: true
});
serviceSG.connections.allowFrom(loadBalancer, Port.tcp(80));
const domainZone = HostedZone.fromLookup(this, 'Zone', { domainName: props.domainZone });
new ARecord(this, "DNS", {
constructor(parent: cdk.App, name: string, props: TriviaBackendStackProps) {
super(parent, name, props);
// Network infrastructure
const vpc = new Vpc(this, 'VPC', { maxAzs: 2 });
const cluster = new Cluster(this, 'Cluster', {
clusterName: props.domainName.replace(/\./g, '-'),
vpc
});
// Configuration parameters
const domainZone = HostedZone.fromLookup(this, 'Zone', { domainName: props.domainZone });
const imageRepo = Repository.fromRepositoryName(this, 'Repo', 'reinvent-trivia-backend');
const tag = (process.env.IMAGE_TAG) ? process.env.IMAGE_TAG : 'latest';
const image = ContainerImage.fromEcrRepository(imageRepo, tag)
// Lookup pre-existing TLS certificate
const certificateArn = StringParameter.fromStringParameterAttributes(this, 'CertArnParameter', {
parameterName: 'CertificateArn-' + props.domainName
}).stringValue;
const certificate = Certificate.fromCertificateArn(this, 'Cert', certificateArn);
constructor(parent, id, props) {
super(parent, id, props);
const vpc = new ec2.Vpc(this, 'GreetingVpc', { maxAZs: 2 });
// Create an ECS cluster
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
// Add capacity to it
cluster.addCapacity('greeter-capacity', {
instanceType: new ec2.InstanceType('t3.xlarge'),
minCapacity: 3,
maxCapacity: 3
});
// Name service
const nameTaskDefinition = new ecs.Ec2TaskDefinition(this, 'name-task-definition', {});
const nameContainer = nameTaskDefinition.addContainer('name', {
image: ecs.ContainerImage.fromRegistry('nathanpeck/name'),
constructor(parent, id, props) {
super(parent, id, props);
// Network to run everything in
const vpc = new ec2.Vpc(this, 'NpmFollowerVpc', {
maxAZs: 2,
natGateways: 1
});
// A table to store the list of changelogs and their metadata in
const changelogsTable = new dynamodb.Table(this, 'Changelogs', {
partitionKey: { name: 'changelog', type: dynamodb.AttributeType.STRING },
billingMode: dynamodb.BillingMode.Provisioned
});
const readScaling = changelogsTable.autoScaleReadCapacity({
minCapacity: 211,
maxCapacity: 300
});
readScaling.scaleOnUtilization({
constructor(scope: Construct, id: string, props: ClusterProps = { }) {
super(scope, id, {
physicalName: props.clusterName,
});
this.node.addWarning(`The @aws-cdk/aws-eks-legacy module will no longer be released as part of the AWS CDK starting March 1st, 2020. Please refer to https://github.com/aws/aws-cdk/issues/5544 for upgrade instructions`);
const stack = Stack.of(this);
this.vpc = props.vpc || new ec2.Vpc(this, 'DefaultVpc');
this.version = props.version;
this.tagSubnets();
this.role = props.role || new iam.Role(this, 'ClusterRole', {
assumedBy: new iam.ServicePrincipal('eks.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSClusterPolicy'),
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSServicePolicy'),
],
});
const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'ControlPlaneSecurityGroup', {
vpc: this.vpc,
description: 'EKS Control Plane Security Group',
});
super(scope, id, {
physicalName: props.clusterName,
});
const cluster = new CfnCluster(this, 'Resource', {
clusterName: this.physicalName,
});
this.clusterArn = this.getResourceArnAttribute(cluster.attrArn, {
service: 'ecs',
resource: 'cluster',
resourceName: this.physicalName,
});
this.clusterName = this.getResourceNameAttribute(cluster.ref);
this.vpc = props.vpc || new ec2.Vpc(this, 'Vpc', { maxAzs: 2 });
this._defaultCloudMapNamespace = props.defaultCloudMapNamespace !== undefined
? this.addDefaultCloudMapNamespace(props.defaultCloudMapNamespace)
: undefined;
this._autoscalingGroup = props.capacity !== undefined
? this.addCapacity("DefaultAutoScalingGroup", props.capacity)
: undefined;
}