Skip to content

Instantly share code, notes, and snippets.

@skorfmann
Last active February 16, 2023 11:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skorfmann/8da4eb64845e10f5937655520d53ac14 to your computer and use it in GitHub Desktop.
Save skorfmann/8da4eb64845e10f5937655520d53ac14 to your computer and use it in GitHub Desktop.
Example for Fargate Task Defintion with ECR Docker Image Asset - https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecr-assets.DockerImageAsset.html
import ecs = require('@aws-cdk/aws-ecs');
import { DockerImageAsset } from '@aws-cdk/aws-ecr-assets';
import path = require('path')
export interface FooFargateProps {
}
export class FooFargate extends cdk.Construct {
constructor(scope: cdk.Construct, id: string, props: FooFargateProps = {}) {
super(scope, id);
const taskDefinition = new ecs.FargateTaskDefinition(this, 'FooDefinition', {
memoryLimitMiB: 2048,
cpu: 1024
});
const asset = new DockerImageAsset(this, 'FooEcrImage', {
directory: path.join(__dirname, 'assets'),
});
asset.repository.grantPull(taskDefinition.taskRole)
const logging = new ecs.AwsLogDriver({
streamPrefix: "foo"
})
taskDefinition.addContainer('DefaultContainer', {
image: ecs.ContainerImage.fromEcrRepository(asset.repository),
memoryReservationMiB: 2048,
cpu: 1024,
logging
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment