question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom_resources: explain how to do replacement with AwsCustomResource

See original GitHub issue

What is the problem?

We can use AwsCustomResource to map custom resource create/update/delete to an SDK call. However, there are updates that actually require a new resource to be created and the original one deleted.

For example, suppose we are using such a custom resource to manage IoT Core role aliases. The create action maps to createRoleAlias, the update action maps to updateRoleAlias, and the delete action maps to deleteRoleAlias. However, if we are specifically trying to update the role alias name itself, then we cannot just call updateRoleAlias, because under normal circumstances the new role alias does not exist yet and must be created not updated.

Even if some mechanism were added to AwsCustomResource or AwsSdkCall to detect updates requiring replacement, there is still an issue. If the deployment were to fail, CloudFormation will attempt to rollback by issuing another update back to the original parameters. But this would also be detected as a replacement, which would issue another createRoleAlias, which would fail because the original role alias still exists. So now you’d need something akin to ignore_error_codes_matching, but only in the specific case of a rollback after an update requiring replacement.

Reproduction Steps

Use AwsCustomResource to create an IoT Core role alias. Then try to update the role alias name.

What did you expect to happen?

It should be able to handle updates requiring replacement, or the construct should be deprecated with a warning that it cannot be used in most cases.

What actually happened?

It tried to update a non-existent role alias and failed.

CDK CLI Version

1.130.0

Framework Version

No response

Node.js Version

16.13.0

OS

Alpine 3.14

Language

Python

Language Version

3.9

Other information

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
gshpychkacommented, May 10, 2022

@gshpychka No, it’s a bug. As soon as you use AwsCustomResource, you get stuck in a bad state where you literally cannot perform certain updates. Either it needs to be fixed to function properly, or a warning needs to be added to the documentation not to use it.

No, it’s not as soon as you use it, it’s only when you use it with specific API actions. It was meant for the simplest cases, you can use a lambda backed custom resource for something more complex.

1reaction
gshpychkacommented, May 10, 2022

@rix0rrr Please re-add the bug label.

This isn’t a bug, it’s a feature request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/custom-resources module
In this case you can use the AwsCustomResource construct. This construct creates a custom resource that can be customized to make specific API...
Read more >
Advanced Custom Resources with AWS CDK
In Part 1, we learned what AWS CloudFormation custom resources are and how to create a custom resource using the AWS CDK's AWSCustomResource...
Read more >
AwsCustomResource leaks assumed role to other custom ...
I have a pattern which uses AWS Custom Resources in this fashion too for manipulating remote/spoke account Route53ResolverRule associations via ...
Read more >
I need help understanding what is AwsCustomResource. ...
This would be difficult as many resources do not have a ... Note that custom resources do not need to create any resources...
Read more >
How to use the PhysicalResourceId for CloudFormation ...
Choosing the PhysicalResourceId is critical when you define your own custom resources. It can make or break the reliability of your code, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found