Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected getDefaultCluster(scope: Construct, vpc?: IVpc): Cluster {
// magic string to avoid collision with user-defined constructs
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
const stack = Stack.of(scope);
return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
}
protected getDefaultCluster(scope: cdk.Construct, vpc?: IVpc): Cluster {
// magic string to avoid collision with user-defined constructs
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
const stack = cdk.Stack.of(scope);
return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
}
protected getDefaultCluster(scope: cdk.Construct, vpc?: IVpc): Cluster {
// magic string to avoid collision with user-defined constructs
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
const stack = cdk.Stack.of(scope);
return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
}
}
},
// cache:{
// paths:[
// '/root/.m2/**/*',
// ]
// }
})
});
// const vpc = Vpc.fromLookup(this, 'CoffeeShopCdkStack/CoffeeShopVPC',{
// vpcName: 'CoffeeShopCdkStack/CoffeeShopVPC',
// isDefault: false,
// });
const cluster = new ecs.Cluster(this, 'Cluster', {
clusterName: 'coffeeshop',
vpc
});
const taskDefinition = new ecs.TaskDefinition(this, 'orders-web-Task', {
compatibility: ecs.Compatibility.FARGATE,
memoryMiB: '512',
cpu: '256',
});
taskDefinition.addContainer('defaultContainer', {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
logging: new ecs.AwsLogDriver({
streamPrefix: 'coffeeshop',
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);
protected getDefaultCluster(scope: Construct, vpc?: IVpc): Cluster {
// magic string to avoid collision with user-defined constructs
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
const stack = Stack.of(scope);
return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
}
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'),
memoryLimitMiB: 128
});
});
// Define the ECS task
const cluster = new ecs.Cluster(this, 'Cluster', { vpc });
const taskDefinition = new ecs.FargateTaskDefinition(this, 'taskDefinition', {});
taskDefinition.addContainer('cloudmapper-container', {
image: ecs.ContainerImage.fromAsset('./resources'),
memoryLimitMiB: 512,
cpu: 256,
environment: {
S3_BUCKET: config['s3_bucket'],
MINIMUM_ALERT_SEVERITY: config['minimum_alert_severity']
},
logging: new ecs.AwsLogDriver({
streamPrefix: 'cloudmapper',
logRetention: logs.RetentionDays.TWO_WEEKS
})
});
// Grant the ability to assume the IAM role in any account
taskDefinition.addToTaskRolePolicy(new iam.PolicyStatement({
resources: ["arn:aws:iam::*:role/"+config['iam_role']],
actions: ['sts:AssumeRole']
}));
// Grant the ability to read and write the files from the S3 bucket
taskDefinition.addToTaskRolePolicy(new iam.PolicyStatement({
resources: ["arn:aws:s3:::"+config['s3_bucket']],
actions: ['s3:ListBucket']
}));
return false;
});
// Define the follower application.
const followerDefinition = new ecs.FargateTaskDefinition(this, 'NpmFollowerDefinition', {});
followerDefinition.addContainer('npm-follower', {
image: ecs.ContainerImage.fromAsset('./app/npm-follower'),
memoryMiB: 512,
cpu: 256,
environment: {
CHANGELOGS_TABLE_NAME: props.changelogsTable.tableName,
DISCOVERED_TOPIC_NAME: props.toCrawlTopic.topicArn
},
logging: new ecs.AwsLogDriver({
streamPrefix: 'npm-follower'
})
});
// Grant this application access to the DynamoDB table and SNS topic
props.changelogsTable.grantReadWriteData(followerDefinition.taskRole);
props.toCrawlTopic.grantPublish(followerDefinition.taskRole);
// Launch the image as a service in Fargate
this.npmFollower = new ecs.FargateService(this, 'NpmFollower', {
assignPublicIp: true,
cluster: props.cluster, // Required
cpu: '256',
memoryMiB: '512',
desiredCount: 1,
taskDefinition: followerDefinition,
constructor(scope: Construct, id: string, props: QueueProcessingEc2ServiceProps) {
super(scope, id, props);
// Create a Task Definition for the container to start
this.taskDefinition = new Ec2TaskDefinition(this, 'QueueProcessingTaskDef');
this.taskDefinition.addContainer('QueueProcessingContainer', {
image: props.image,
memoryLimitMiB: props.memoryLimitMiB,
memoryReservationMiB: props.memoryReservationMiB,
cpu: props.cpu,
command: props.command,
environment: this.environment,
secrets: this.secrets,
logging: this.logDriver
});
// Create an ECS service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
this.service = new Ec2Service(this, 'QueueProcessingService', {
cluster: this.cluster,
desiredCount: this.desiredCount,