Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
// 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,
protected createAWSLogDriver(prefix: string): AwsLogDriver {
return new AwsLogDriver({ streamPrefix: prefix });
}
}
private createAWSLogDriver(prefix: string): AwsLogDriver {
return new AwsLogDriver({ streamPrefix: prefix });
}
}
protected createAWSLogDriver(prefix: string): AwsLogDriver {
return new AwsLogDriver({ streamPrefix: prefix });
}
}
cpu: '2048',
memoryMiB: '4096'
});
this.container = this.workerDefinition.addContainer('worker', {
image: ecs.ContainerImage.fromAsset(this, 'worker-image', {
directory: './worker'
}),
cpu: 2048,
memoryLimitMiB: 4096,
environment: {
QUEUE_URL: props.screenshotQueue.queueUrl,
TABLE: props.screenshotTable.tableName,
BUCKET: props.screenshotBucket.bucketName
},
logging: new ecs.AwsLogDriver(this, 'worker-logs', {
streamPrefix: 'worker'
})
});
this.worker = new ecs.FargateService(this, 'worker', {
cluster: props.cluster,
desiredCount: 2,
taskDefinition: this.workerDefinition
});
props.screenshotQueue.grantConsumeMessages(this.workerDefinition.taskRole);
props.screenshotTable.grantReadWriteData(this.workerDefinition.taskRole);
props.screenshotBucket.grantReadWrite(this.workerDefinition.taskRole);
}
}
protected createAWSLogDriver(prefix: string): AwsLogDriver {
return new AwsLogDriver({ streamPrefix: prefix });
}
}
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',
})
}).addPortMappings({
containerPort: 8080
});
const fargatesvc = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'AlbSvc', {
cluster,
taskDefinition,
})
const fargateTaskRole = fargatesvc.service.taskDefinition.taskRole;
fargateTaskRole.addToPolicy(new iam.PolicyStatement({
resources: ['*'],
actions: ['events:*']
}));