diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index 4899ba712181e..0b23c72829556 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -186,7 +186,7 @@ Alternatively, you can specify a custom image using one of the static methods on Hub. * Use `.fromEcrRepository(repo[, tag])` to reference an image available in an ECR repository. -* Use `.fromAsset(this, id, { directory: dir })` to use an image created from a +* Use `.fromAsset(directory)` to use an image created from a local asset. The following example shows how to define an image from a Docker asset: diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json index 3aee844753d35..753d171830169 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.expected.json @@ -346,189 +346,9 @@ "ClusterEB0386A7": { "Type": "AWS::ECS::Cluster" }, - "ImageAdoptRepositoryE1E84E35": { - "Type": "Custom::ECRAdoptedRepository", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", - "Arn" - ] - }, - "RepositoryName": { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "ImageImageName5E684353" - } - ] - } - ] - } - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] - }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": { - "Fn::Join": [ - "", - [ - "lambda.", - { - "Ref": "AWS::URLSuffix" - } - ] - ] - } - } - } - ], - "Version": "2012-10-17" - }, - "ManagedPolicyArns": [ - { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ] - ] - } - ] - } - }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C": { - "Type": "AWS::IAM::Policy", - "Properties": { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "ecr:GetRepositoryPolicy", - "ecr:SetRepositoryPolicy", - "ecr:DeleteRepository", - "ecr:ListImages", - "ecr:BatchDeleteImage" - ], - "Effect": "Allow", - "Resource": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":ecr:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":repository/", - { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "ImageImageName5E684353" - } - ] - } - ] - } - ] - ] - } - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "Roles": [ - { - "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - } - ] - } - }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": { - "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6" - }, - "S3Key": { - "Fn::Join": [ - "", - [ - { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "||", - { - "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276" - } - ] - } - ] - }, - { - "Fn::Select": [ - 1, - { - "Fn::Split": [ - "||", - { - "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276" - } - ] - } - ] - } - ] - ] - } - }, - "Handler": "handler.handler", - "Role": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Timeout": 300 - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] + "FargateServiceLoggingLogGroup9B16742A": { + "Type": "AWS::Logs::LogGroup", + "DeletionPolicy": "Retain" }, "FargateServiceLBB353E155": { "Type": "AWS::ElasticLoadBalancingV2::LoadBalancer", @@ -692,7 +512,7 @@ ":repository/", { "Fn::GetAtt": [ - "ImageAdoptRepositoryE1E84E35", + "FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419", "RepositoryName" ] } @@ -729,7 +549,7 @@ ":repository/", { "Fn::GetAtt": [ - "ImageAdoptRepositoryE1E84E35", + "FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419", "RepositoryName" ] } @@ -743,7 +563,7 @@ ".amazonaws.com/", { "Fn::GetAtt": [ - "ImageAdoptRepositoryE1E84E35", + "FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419", "RepositoryName" ] }, @@ -755,7 +575,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "ImageImageName5E684353" + "Ref": "FargateServiceTaskDefwebAssetImageImageNameDC0B98D5" } ] } @@ -811,6 +631,34 @@ "Volumes": [] } }, + "FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419": { + "Type": "Custom::ECRAdoptedRepository", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", + "Arn" + ] + }, + "RepositoryName": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "FargateServiceTaskDefwebAssetImageImageNameDC0B98D5" + } + ] + } + ] + } + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] + }, "FargateServiceTaskDefExecutionRole9194820E": { "Type": "AWS::IAM::Role", "Properties": { @@ -869,7 +717,7 @@ ":repository/", { "Fn::GetAtt": [ - "ImageAdoptRepositoryE1E84E35", + "FargateServiceTaskDefwebAssetImageAdoptRepositoryCDAFD419", "RepositoryName" ] } @@ -906,10 +754,6 @@ ] } }, - "FargateServiceLoggingLogGroup9B16742A": { - "Type": "AWS::Logs::LogGroup", - "DeletionPolicy": "Retain" - }, "FargateServiceECC8084D": { "Type": "AWS::ECS::Service", "Properties": { @@ -999,24 +843,162 @@ }, "ToPort": 8000 } - } - }, - "Parameters": { - "ImageImageName5E684353": { - "Type": "String", - "Description": "ECR repository name and tag asset \"aws-ecs-integ/Image\"" }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { - "Type": "String", - "Description": "S3 bucket for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "lambda.", + { + "Ref": "AWS::URLSuffix" + } + ] + ] + } + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276": { - "Type": "String", - "Description": "S3 key for asset version \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "ecr:GetRepositoryPolicy", + "ecr:SetRepositoryPolicy", + "ecr:DeleteRepository", + "ecr:ListImages", + "ecr:BatchDeleteImage" + ], + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":ecr:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":repository/", + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "FargateServiceTaskDefwebAssetImageImageNameDC0B98D5" + } + ] + } + ] + } + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "Roles": [ + { + "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + } + ] + } }, - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeArtifactHash8BCBAA49": { - "Type": "String", - "Description": "Artifact hash for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": { + "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6" + }, + "S3Key": { + "Fn::Join": [ + "", + [ + { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "||", + { + "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276" + } + ] + } + ] + }, + { + "Fn::Select": [ + 1, + { + "Fn::Split": [ + "||", + { + "Ref": "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276" + } + ] + } + ] + } + ] + ] + } + }, + "Handler": "handler.handler", + "Role": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Timeout": 300 + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] } }, "Outputs": { @@ -1036,5 +1018,23 @@ ] } } + }, + "Parameters": { + "FargateServiceTaskDefwebAssetImageImageNameDC0B98D5": { + "Type": "String", + "Description": "ECR repository name and tag asset \"aws-ecs-integ/FargateService/TaskDef/web/AssetImage\"" + }, + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { + "Type": "String", + "Description": "S3 bucket for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + }, + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3VersionKey393B7276": { + "Type": "String", + "Description": "S3 key for asset version \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + }, + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeArtifactHash8BCBAA49": { + "Type": "String", + "Description": "Artifact hash for asset \"aws-ecs-integ/AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c/Code\"" + } } -} +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.ts b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.ts index 3e1f7ab5b35c5..9d296d9208388 100644 --- a/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.ts +++ b/packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.asset-image.ts @@ -17,9 +17,7 @@ Array.isArray(path); const fargateService = new ecsPatterns.LoadBalancedFargateService(stack, "FargateService", { cluster, containerPort: 8000, - image: new ecs.AssetImage(stack, 'Image', { - directory: path.join(__dirname, '..', 'demo-image') - }) + image: new ecs.AssetImage(path.join(__dirname, '..', 'demo-image')), }); // CfnOutput the DNS where you can access your service diff --git a/packages/@aws-cdk/aws-ecs/README.md b/packages/@aws-cdk/aws-ecs/README.md index 2e59d5b54300f..c9464548ca846 100644 --- a/packages/@aws-cdk/aws-ecs/README.md +++ b/packages/@aws-cdk/aws-ecs/README.md @@ -201,7 +201,7 @@ obtained from either DockerHub or from ECR repositories, or built directly from * `ecs.ContainerImage.fromRegistry(imageName, { credentials: mySecret })`: use a private image that requires credentials. * `ecs.ContainerImage.fromEcrRepository(repo, tag)`: use the given ECR repository as the image to start. If no tag is provided, "latest" is assumed. -* `ecs.ContainerImage.fromAsset(this, 'Image', { directory: './image' })`: build and upload an +* `ecs.ContainerImage.fromAsset('./image')`: build and upload an image directly from a `Dockerfile` in your source directory. ## Service @@ -307,9 +307,7 @@ import targets = require('@aws-cdk/aws-events-targets'); // Create a Task Definition for the container to start const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef'); taskDefinition.addContainer('TheContainer', { - image: ecs.ContainerImage.fromAsset(this, 'EventImage', { - directory: path.resolve(__dirname, '..', 'eventhandler-image') - }), + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, '..', 'eventhandler-image')), memoryLimitMiB: 256, logging: new ecs.AwsLogDriver(this, 'TaskLogging', { streamPrefix: 'EventDemo' }) }); diff --git a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts index d05de2d082f62..59f8e08e0c660 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-definition.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-definition.ts @@ -1,7 +1,7 @@ import iam = require('@aws-cdk/aws-iam'); import cdk = require('@aws-cdk/cdk'); import { NetworkMode, TaskDefinition } from './base/task-definition'; -import { ContainerImage } from './container-image'; +import { ContainerImage, ContainerImageConfig } from './container-image'; import { CfnTaskDefinition } from './ecs.generated'; import { LinuxParameters } from './linux-parameters'; import { LogDriver } from './log-drivers/log-driver'; @@ -247,6 +247,8 @@ export class ContainerDefinition extends cdk.Construct { */ private readonly links = new Array(); + private readonly imageConfig: ContainerImageConfig; + constructor(scope: cdk.Construct, id: string, private readonly props: ContainerDefinitionProps) { super(scope, id); this.essential = props.essential !== undefined ? props.essential : true; @@ -254,7 +256,7 @@ export class ContainerDefinition extends cdk.Construct { this.memoryLimitSpecified = props.memoryLimitMiB !== undefined || props.memoryReservationMiB !== undefined; this.linuxParameters = props.linuxParameters; - props.image.bind(this); + this.imageConfig = props.image.bind(this, this); if (props.logging) { props.logging.bind(this); } props.taskDefinition._linkContainer(this); } @@ -395,7 +397,7 @@ export class ContainerDefinition extends cdk.Construct { entryPoint: this.props.entryPoint, essential: this.essential, hostname: this.props.hostname, - image: this.props.image.imageName, + image: this.imageConfig.imageName, memory: this.props.memoryLimitMiB, memoryReservation: this.props.memoryReservationMiB, mountPoints: this.mountPoints.map(renderMountPoint), @@ -403,7 +405,7 @@ export class ContainerDefinition extends cdk.Construct { portMappings: this.portMappings.map(renderPortMapping), privileged: this.props.privileged, readonlyRootFilesystem: this.props.readonlyRootFilesystem, - repositoryCredentials: this.props.image.toRepositoryCredentialsJson(), + repositoryCredentials: this.imageConfig.repositoryCredentials, ulimits: this.ulimits.map(renderUlimit), user: this.props.user, volumesFrom: this.volumesFrom.map(renderVolumeFrom), diff --git a/packages/@aws-cdk/aws-ecs/lib/container-image.ts b/packages/@aws-cdk/aws-ecs/lib/container-image.ts index 9b7b9e11b02bc..780708dba27b8 100644 --- a/packages/@aws-cdk/aws-ecs/lib/container-image.ts +++ b/packages/@aws-cdk/aws-ecs/lib/container-image.ts @@ -23,27 +23,34 @@ export abstract class ContainerImage { /** * Reference an image that's constructed directly from sources on disk + * + * @param directory The directory containing the Dockerfile */ - public static fromAsset(scope: cdk.Construct, id: string, props: AssetImageProps) { - return new AssetImage(scope, id, props); + public static fromAsset(directory: string, props: AssetImageProps = {}) { + return new AssetImage(directory, props); } /** - * Name of the image + * Called when the image is used by a ContainerDefinition */ - public abstract readonly imageName: string; + public abstract bind(scope: cdk.Construct, containerDefinition: ContainerDefinition): ContainerImageConfig; +} +/** + * Configuration for producing a container image + */ +export interface ContainerImageConfig { /** - * Called when the image is used by a ContainerDefinition + * Name of the image */ - public abstract bind(containerDefinition: ContainerDefinition): void; + readonly imageName: string; /** - * Render the Repository credentials to the CloudFormation object + * Credentials to use to access the repository */ - public abstract toRepositoryCredentialsJson(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined; + readonly repositoryCredentials?: CfnTaskDefinition.RepositoryCredentialsProperty; } import { AssetImage, AssetImageProps } from './images/asset-image'; import { EcrImage } from './images/ecr'; -import { RepositoryImage, RepositoryImageProps } from './images/repository'; \ No newline at end of file +import { RepositoryImage, RepositoryImageProps } from './images/repository'; diff --git a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts index a85dac7eeb7b9..231ae5eb0f179 100644 --- a/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts +++ b/packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts @@ -1,15 +1,9 @@ import { DockerImageAsset } from '@aws-cdk/assets-docker'; import cdk = require('@aws-cdk/cdk'); import { ContainerDefinition } from '../container-definition'; -import { ContainerImage } from '../container-image'; -import { CfnTaskDefinition } from '../ecs.generated'; +import { ContainerImage, ContainerImageConfig } from '../container-image'; export interface AssetImageProps { - /** - * The directory where the Dockerfile is stored - */ - readonly directory: string; - /** * Build args to pass to the `docker build` command * @@ -19,28 +13,27 @@ export interface AssetImageProps { } /** - * An image that will be built at synthesis time + * An image that will be built at synthesis time from a directory with a Dockerfile */ export class AssetImage extends ContainerImage { - private readonly asset: DockerImageAsset; - - constructor(scope: cdk.Construct, id: string, props: AssetImageProps) { + /** + * Create an AssetImage + * + * @param directory The directory containing the Dockerfile + */ + constructor(private readonly directory: string, private readonly props: AssetImageProps = {}) { super(); - this.asset = new DockerImageAsset(scope, id, { - directory: props.directory, - buildArgs: props.buildArgs, - }); - } - - public bind(containerDefinition: ContainerDefinition): void { - this.asset.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole()); } - public toRepositoryCredentialsJson(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined { - return undefined; - } + public bind(scope: cdk.Construct, containerDefinition: ContainerDefinition): ContainerImageConfig { + const asset = new DockerImageAsset(scope, 'AssetImage', { + directory: this.directory, + buildArgs: this.props.buildArgs, + }); + asset.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole()); - public get imageName() { - return this.asset.imageUri; + return { + imageName: asset.imageUri, + }; } } diff --git a/packages/@aws-cdk/aws-ecs/lib/images/ecr.ts b/packages/@aws-cdk/aws-ecs/lib/images/ecr.ts index 0d2741d577d6b..a5b161bf41dc6 100644 --- a/packages/@aws-cdk/aws-ecs/lib/images/ecr.ts +++ b/packages/@aws-cdk/aws-ecs/lib/images/ecr.ts @@ -1,26 +1,23 @@ import ecr = require('@aws-cdk/aws-ecr'); +import { Construct } from '@aws-cdk/cdk'; import { ContainerDefinition } from '../container-definition'; -import { ContainerImage } from '../container-image'; -import { CfnTaskDefinition } from '../ecs.generated'; +import { ContainerImage, ContainerImageConfig } from '../container-image'; /** * An image from an ECR repository */ export class EcrImage extends ContainerImage { public readonly imageName: string; - private readonly repository: ecr.IRepository; - constructor(repository: ecr.IRepository, tag: string) { + constructor(private readonly repository: ecr.IRepository, private readonly tag: string) { super(); - this.imageName = repository.repositoryUriForTag(tag); - this.repository = repository; } - public bind(containerDefinition: ContainerDefinition): void { + public bind(_scope: Construct, containerDefinition: ContainerDefinition): ContainerImageConfig { this.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole()); - } - public toRepositoryCredentialsJson(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined { - return undefined; + return { + imageName: this.repository.repositoryUriForTag(this.tag) + }; } } diff --git a/packages/@aws-cdk/aws-ecs/lib/images/repository.ts b/packages/@aws-cdk/aws-ecs/lib/images/repository.ts index 67126e466795a..15d5f6bd7be0d 100644 --- a/packages/@aws-cdk/aws-ecs/lib/images/repository.ts +++ b/packages/@aws-cdk/aws-ecs/lib/images/repository.ts @@ -1,39 +1,34 @@ import secretsmanager = require('@aws-cdk/aws-secretsmanager'); +import { Construct } from '@aws-cdk/cdk'; import { ContainerDefinition } from "../container-definition"; -import { ContainerImage } from "../container-image"; -import { CfnTaskDefinition } from '../ecs.generated'; +import { ContainerImage, ContainerImageConfig } from "../container-image"; export interface RepositoryImageProps { - /** - * Optional secret that houses credentials for the image registry - */ - readonly credentials?: secretsmanager.ISecret; + /** + * Optional secret that houses credentials for the image registry + */ + readonly credentials?: secretsmanager.ISecret; } /** * A container image hosted on DockerHub or another online registry */ export class RepositoryImage extends ContainerImage { - public readonly imageName: string; - private credentialsSecret?: secretsmanager.ISecret; - - constructor(imageName: string, props: RepositoryImageProps = {}) { + constructor(private readonly imageName: string, private readonly props: RepositoryImageProps = {}) { super(); - this.imageName = imageName; - this.credentialsSecret = props.credentials; } - public bind(containerDefinition: ContainerDefinition): void { - if (this.credentialsSecret) { - this.credentialsSecret.grantRead(containerDefinition.taskDefinition.obtainExecutionRole()); + public bind(_scope: Construct, containerDefinition: ContainerDefinition): ContainerImageConfig { + if (this.props.credentials) { + this.props.credentials.grantRead(containerDefinition.taskDefinition.obtainExecutionRole()); } - } - public toRepositoryCredentialsJson(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined { - if (!this.credentialsSecret) { return undefined; } return { - credentialsParameter: this.credentialsSecret.secretArn + imageName: this.imageName, + repositoryCredentials: this.props.credentials && { + credentialsParameter: this.props.credentials.secretArn + } }; } } diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json index 2a5586901642c..ce78f1f515fa0 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.expected.json @@ -674,7 +674,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -711,7 +711,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -725,7 +725,7 @@ ".amazonaws.com/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] }, @@ -737,7 +737,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -787,6 +787,34 @@ "Volumes": [] } }, + "TaskDefTheContainerAssetImageAdoptRepository997406C3": { + "Type": "Custom::ECRAdoptedRepository", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", + "Arn" + ] + }, + "RepositoryName": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" + } + ] + } + ] + } + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] + }, "TaskDefExecutionRoleB4775C97": { "Type": "AWS::IAM::Role", "Properties": { @@ -845,7 +873,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -952,33 +980,9 @@ ] } }, - "EventImageAdoptRepositoryDFAAC242": { - "Type": "Custom::ECRAdoptedRepository", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", - "Arn" - ] - }, - "RepositoryName": { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "EventImageImageNameE972A8B1" - } - ] - } - ] - } - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] + "TaskLoggingLogGroupC7E938D4": { + "Type": "AWS::Logs::LogGroup", + "DeletionPolicy": "Retain" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { "Type": "AWS::IAM::Role", @@ -1059,7 +1063,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -1136,10 +1140,6 @@ "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" ] }, - "TaskLoggingLogGroupC7E938D4": { - "Type": "AWS::Logs::LogGroup", - "DeletionPolicy": "Retain" - }, "Rule4C995B7F": { "Type": "AWS::Events::Rule", "Properties": { @@ -1173,9 +1173,9 @@ } }, "Parameters": { - "EventImageImageNameE972A8B1": { + "TaskDefTheContainerAssetImageImageName92ECAC22": { "Type": "String", - "Description": "ECR repository name and tag asset \"aws-ecs-integ-ecs/EventImage\"" + "Description": "ECR repository name and tag asset \"aws-ecs-integ-ecs/TaskDef/TheContainer/AssetImage\"" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { "Type": "String", diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.ts b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.ts index 2fa77dbe3d1e7..98245c87cc115 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.ts +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-ec2-task.lit.ts @@ -23,9 +23,7 @@ class EventStack extends cdk.Stack { // Create a Task Definition for the container to start const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef'); taskDefinition.addContainer('TheContainer', { - image: ecs.ContainerImage.fromAsset(this, 'EventImage', { - directory: path.resolve(__dirname, 'eventhandler-image') - }), + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, 'eventhandler-image')), memoryLimitMiB: 256, logging: new ecs.AwsLogDriver(this, 'TaskLogging', { streamPrefix: 'EventDemo' }) }); diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json index f1582b411a944..09fd3e31e2158 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.expected.json @@ -255,7 +255,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -292,7 +292,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -306,7 +306,7 @@ ".amazonaws.com/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] }, @@ -318,7 +318,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -369,6 +369,34 @@ "Volumes": [] } }, + "TaskDefTheContainerAssetImageAdoptRepository997406C3": { + "Type": "Custom::ECRAdoptedRepository", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", + "Arn" + ] + }, + "RepositoryName": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" + } + ] + } + ] + } + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] + }, "TaskDefExecutionRoleB4775C97": { "Type": "AWS::IAM::Role", "Properties": { @@ -427,7 +455,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -726,33 +754,9 @@ } } }, - "EventImageAdoptRepositoryDFAAC242": { - "Type": "Custom::ECRAdoptedRepository", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", - "Arn" - ] - }, - "RepositoryName": { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "EventImageImageNameE972A8B1" - } - ] - } - ] - } - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] + "TaskLoggingLogGroupC7E938D4": { + "Type": "AWS::Logs::LogGroup", + "DeletionPolicy": "Retain" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { "Type": "AWS::IAM::Role", @@ -833,7 +837,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -910,10 +914,6 @@ "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" ] }, - "TaskLoggingLogGroupC7E938D4": { - "Type": "AWS::Logs::LogGroup", - "DeletionPolicy": "Retain" - }, "Rule4C995B7F": { "Type": "AWS::Events::Rule", "Properties": { @@ -1079,9 +1079,9 @@ } }, "Parameters": { - "EventImageImageNameE972A8B1": { + "TaskDefTheContainerAssetImageImageName92ECAC22": { "Type": "String", - "Description": "ECR repository name and tag asset \"aws-ecs-integ-fargate/EventImage\"" + "Description": "ECR repository name and tag asset \"aws-ecs-integ-fargate/TaskDef/TheContainer/AssetImage\"" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { "Type": "String", diff --git a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.ts b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.ts index 473e451e3911b..e00c0bb5cd6d5 100644 --- a/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.ts +++ b/packages/@aws-cdk/aws-events-targets/test/ecs/integ.event-fargate-task.ts @@ -20,9 +20,7 @@ class EventStack extends cdk.Stack { // Create a Task Definition for the container to start const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef'); taskDefinition.addContainer('TheContainer', { - image: ecs.ContainerImage.fromAsset(this, 'EventImage', { - directory: path.resolve(__dirname, 'eventhandler-image') - }), + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, 'eventhandler-image')), logging: new ecs.AwsLogDriver(this, 'TaskLogging', { streamPrefix: 'EventDemo' }) }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json index f8d6494414d5b..00fbfec8cecac 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.expected.json @@ -160,9 +160,6 @@ } } }, - "FargateClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic49146C10": { - "Type": "AWS::SNS::Topic" - }, "FargateClusterDefaultAutoScalingGroupDrainECSHookFunctionServiceRole7FEDCD32": { "Type": "AWS::IAM::Role", "Properties": { @@ -396,6 +393,9 @@ ] } }, + "FargateClusterDefaultAutoScalingGroupLifecycleHookDrainHookTopic49146C10": { + "Type": "AWS::SNS::Topic" + }, "FargateClusterDefaultAutoScalingGroupLifecycleHookDrainHook2AE13680": { "Type": "AWS::AutoScaling::LifecycleHook", "Properties": { @@ -482,7 +482,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -519,7 +519,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -533,7 +533,7 @@ ".amazonaws.com/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] }, @@ -545,7 +545,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -595,6 +595,34 @@ "Volumes": [] } }, + "TaskDefTheContainerAssetImageAdoptRepository997406C3": { + "Type": "Custom::ECRAdoptedRepository", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", + "Arn" + ] + }, + "RepositoryName": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" + } + ] + } + ] + } + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] + }, "TaskDefExecutionRoleB4775C97": { "Type": "AWS::IAM::Role", "Properties": { @@ -653,7 +681,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -690,33 +718,9 @@ ] } }, - "EventImageAdoptRepositoryDFAAC242": { - "Type": "Custom::ECRAdoptedRepository", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", - "Arn" - ] - }, - "RepositoryName": { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "EventImageImageNameE972A8B1" - } - ] - } - ] - } - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] + "TaskLoggingLogGroupC7E938D4": { + "Type": "AWS::Logs::LogGroup", + "DeletionPolicy": "Retain" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { "Type": "AWS::IAM::Role", @@ -797,7 +801,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -874,10 +878,6 @@ "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" ] }, - "TaskLoggingLogGroupC7E938D4": { - "Type": "AWS::Logs::LogGroup", - "DeletionPolicy": "Retain" - }, "StateMachineRoleB840431D": { "Type": "AWS::IAM::Role", "Properties": { @@ -1015,9 +1015,9 @@ } }, "Parameters": { - "EventImageImageNameE972A8B1": { + "TaskDefTheContainerAssetImageImageName92ECAC22": { "Type": "String", - "Description": "ECR repository name and tag asset \"aws-ecs-integ2/EventImage\"" + "Description": "ECR repository name and tag asset \"aws-ecs-integ2/TaskDef/TheContainer/AssetImage\"" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { "Type": "String", diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts index 14e4d3789219d..290e17ae26a56 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.ec2-task.ts @@ -21,7 +21,7 @@ cluster.addCapacity('DefaultAutoScalingGroup', { // Build task definition const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'TaskDef'); taskDefinition.addContainer('TheContainer', { - image: ecs.ContainerImage.fromAsset(stack, 'EventImage', { directory: path.resolve(__dirname, 'eventhandler-image') }), + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, 'eventhandler-image')), memoryLimitMiB: 256, logging: new ecs.AwsLogDriver(stack, 'TaskLogging', { streamPrefix: 'EventDemo' }) }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json index 03a26b042def5..4974306cfeb30 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.expected.json @@ -65,7 +65,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -102,7 +102,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -116,7 +116,7 @@ ".amazonaws.com/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] }, @@ -128,7 +128,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -180,6 +180,34 @@ "Volumes": [] } }, + "TaskDefTheContainerAssetImageAdoptRepository997406C3": { + "Type": "Custom::ECRAdoptedRepository", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", + "Arn" + ] + }, + "RepositoryName": { + "Fn::Select": [ + 0, + { + "Fn::Split": [ + "@sha256:", + { + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" + } + ] + } + ] + } + }, + "DependsOn": [ + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", + "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" + ] + }, "TaskDefExecutionRoleB4775C97": { "Type": "AWS::IAM::Role", "Properties": { @@ -238,7 +266,7 @@ ":repository/", { "Fn::GetAtt": [ - "EventImageAdoptRepositoryDFAAC242", + "TaskDefTheContainerAssetImageAdoptRepository997406C3", "RepositoryName" ] } @@ -275,33 +303,9 @@ ] } }, - "EventImageAdoptRepositoryDFAAC242": { - "Type": "Custom::ECRAdoptedRepository", - "Properties": { - "ServiceToken": { - "Fn::GetAtt": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62c52BE89E9", - "Arn" - ] - }, - "RepositoryName": { - "Fn::Select": [ - 0, - { - "Fn::Split": [ - "@sha256:", - { - "Ref": "EventImageImageNameE972A8B1" - } - ] - } - ] - } - }, - "DependsOn": [ - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleDefaultPolicy6BC8737C", - "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" - ] + "TaskLoggingLogGroupC7E938D4": { + "Type": "AWS::Logs::LogGroup", + "DeletionPolicy": "Retain" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17": { "Type": "AWS::IAM::Role", @@ -382,7 +386,7 @@ "Fn::Split": [ "@sha256:", { - "Ref": "EventImageImageNameE972A8B1" + "Ref": "TaskDefTheContainerAssetImageImageName92ECAC22" } ] } @@ -459,10 +463,6 @@ "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cServiceRoleD788AA17" ] }, - "TaskLoggingLogGroupC7E938D4": { - "Type": "AWS::Logs::LogGroup", - "DeletionPolicy": "Retain" - }, "FargateTaskSecurityGroup0BBB27CB": { "Type": "AWS::EC2::SecurityGroup", "Properties": { @@ -622,9 +622,9 @@ } }, "Parameters": { - "EventImageImageNameE972A8B1": { + "TaskDefTheContainerAssetImageImageName92ECAC22": { "Type": "String", - "Description": "ECR repository name and tag asset \"aws-ecs-integ2/EventImage\"" + "Description": "ECR repository name and tag asset \"aws-ecs-integ2/TaskDef/TheContainer/AssetImage\"" }, "AdoptEcrRepositorydbc60defc59544bcaa5c28c95d68f62cCodeS3Bucket92AB06B6": { "Type": "String", diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts index 751c06dd35f5b..f3ec0a6fd26aa 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/integ.fargate-task.ts @@ -20,7 +20,7 @@ const taskDefinition = new ecs.FargateTaskDefinition(stack, 'TaskDef', { cpu: 256 }); taskDefinition.addContainer('TheContainer', { - image: ecs.ContainerImage.fromAsset(stack, 'EventImage', { directory: path.resolve(__dirname, 'eventhandler-image') }), + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, 'eventhandler-image')), memoryLimitMiB: 256, logging: new ecs.AwsLogDriver(stack, 'TaskLogging', { streamPrefix: 'EventDemo' }) });