I am developing using AWS CDK and I often hit this error. I understand it is important. however when developing, I want to do some trial and error deploy/destroy.
This error is very troublesome.
Is there any command to overwrite existing S3 and ECR such as --force?
11:40:07 | CREATE_FAILED | AWS::ECR::Repository | TestRepoId440F76C3
my-repo-name already exists in stack arn:aws:cloudformation:ap-northeast-1:678100228133:stack/CdkVrStack/9e712790-7ebc-11ec-9b4b-0ad504232487
11:40:07 | CREATE_FAILED | AWS::S3::Bucket | testBucketDF4D7D1A
vr-resource-bucket already exists in stack arn:aws:cloudformation:ap-northeast-1:678100228133:stack/CdkVrStack/9e712790-7ebc-11ec-9b4b-0ad504232487
My stack code is like this below.
export class CdkVrBaseStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const bucket_ = new s3.Bucket(this, 'testBucket', {
bucketName: 'vr-resource-bucket',
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
cors: [{
allowedMethods: [
s3.HttpMethods.GET,
s3.HttpMethods.POST,
s3.HttpMethods.PUT,
s3.HttpMethods.DELETE,
s3.HttpMethods.HEAD,
],
allowedHeaders: ["*"],
allowedOrigins: ["*"],
exposedHeaders: ["ETag"],
maxAge: 3000
}]
});
const lambda_ = new lambda.Function(this, 'TestLambda', {
functionName: 'testLambda',
runtime: lambda.Runtime.PYTHON_3_9,
code: lambda.Code.fromAsset('foo_lambda'),
handler: 'index.handler',
timeout: cdk.Duration.seconds(300),
//role: executionLambdaRole,
//environment: {
// TZ: "Asia/Tokyo",
// SLACK_CHANNEL: slackChannel.stringValue,
//}
});
lambda_.addEventSource(new S3EventSource(bucket_, {
events: [ s3.EventType.OBJECT_CREATED, s3.EventType.OBJECT_REMOVED ],
//filters: [ { prefix: 'subdir/' } ], // optional
}));
const repo_ = new ecr.Repository(this, 'TestRepoId', {
repositoryName: "my-repo-name",
removalPolicy: RemovalPolicy.DESTROY
});
const image_ = new DockerImageAsset(this,'mydockerimageassets',{
directory: path.join(__dirname, '../docker-lambda'),
});
new ecrdeploy.ECRDeployment(this, 'DeployDockerImage', {
src: new ecrdeploy.DockerImageName(image_.imageUri),
dest: new ecrdeploy.DockerImageName(`${repo_.repositoryUri}:latest`),
});
CodePudding user response:
No, that's not an option.
This is the exact reason you should avoid providing physical names for resources. Let the CDK auto-generate them and you will not have these issues.
Refer to the answer to the following question: CREATE_FAILED | AWS::S3::Bucket, the invisible bucket is exist?
