aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
Custom resource not updated after dependent resource is updated (ignores DependsOn and references)
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
### Name of the resource
AWS::CloudFormation::CustomResource
### Resource Name
_No response_
### Issue Description
I've defined a custom resource that invokes a lambda with inline code:
```yml
MyFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: myfunction
Handler: index.handler
Runtime: nodejs14.x
Policies:
- AWSLambdaVPCAccessExecutionRole
InlineCode: |
const cfnResponse = require('cfn-response');
exports.handler = async function(event, context) {
cfnResponse.send(event, context, cfnResponse.SUCCESS);
}
MyCustomResource:
Type: Custom::MyCustomResource
Properties:
ServiceToken: !GetAtt MyFunction.Arn
```
The resource is created successfully; however, it does not get updated by CF when the function is updated.
For instance, when I update the lambda code or add/change its timeout, the lambda gets updated but the custom resource does not (no event on the CF stack and no message in the lambda's logs).
I tried to add `DependsOn` and other types of references, as suggested in [this SO question](https://stackoverflow.com/questions/46479991/dependson-and-cloudformation-custom-resources), but it didn't affect this behavior:
```yml
MyCustomResource:
Type: Custom::MyCustomResource
DependsOn: MyFunction
Properties:
ServiceToken: !GetAtt MyFunction.Arn
Foo: !Ref MyFunction
```
I'm not 100% if this is a bug or something that is just not supported.
### Expected Behavior
The custom resource should be updated and triggered with an `Update` event if another resource that it (directly) `DependsOn` is updated.
### Observed Behavior
The custom resource is not updated/triggerd.
### Test Cases
_No response_
### Other Details
The larger context here is RDS schema migration/changes; every time a new schema change is added (with a code snipped), we want this change to be executed on the RDS from an AWS-based executor and not from our CI.
At first we were using a lambda to execute the migrations, but over time this proved problematic due to timeout limitations.
Therefore, we changed the DB migrations process to run from an ECS task (Fargate). For every new change we build a new image with all of the changes, push it to ECR, and update the task definition to use the new image.
What I'm trying to achieve here is to run the ECS task after it's updated as part of the CF deployment process. I wrote a lambda that will trigger the ECS task (with all the right parameters), and I want it to be triggered for every update to the ECS task definition.
Hence, I'm trying to create a custom resource that will trigger the lambda that invokes the ECS task whenever the ECS task is updated (all in the same stack/template).
Contributor guide
Research direction
The issue names no repository files or tests; it provides an AWS CloudFormation YAML template with inline JavaScript and a custom-resource Lambda entry point. Start by investigating how dependency changes are handled for custom resources; done means establishing whether a directly depended-on resource update produces the custom resource's Update event.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, javascript
- Domain
- cloud, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100