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: 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,
memoryMiB: props.memoryMiB,
publicLoadBalancer: props.publicLoadBalancer,
publicTasks: props.publicTasks,
image: ContainerImage.fromRegistry(props.image),
desiredCount: props.desiredCount,
environment: props.environment,
certificate,
domainName: props.domainName,
domainZone
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);
// Fargate service + load balancer
new ApplicationLoadBalancedFargateService(this, 'Service', {
cluster,
taskImageOptions: { image },
desiredCount: 3,
domainName: props.domainName,
domainZone,
certificate
});
}
}