I'm designing an AWS Lambda function for a Cloudformation Custom Resource as per this documentation.
Upon creation of the Custom Resource, the associated Lambda function should (a) create an external resource, and (b) return the ID associated with that external resource.
Upon the update or deletion of the Custom Resource, the associated Lambda function should take the ID of the existing external resource as a parameter/property, and update/delete that external resource accordingly.
To do so, the CloudFormation stack needs to store that ID returned by the Lambda upon the creation of the Custom Resource. Ideally, it should also associate that ID with the Custom Resource itself.
How can this be achieved?
Example code for the scenario in question:
Resources:
CustomResource:
Type: AWS::CloudFormation::CustomResource
Properties:
ServiceToken:
Fn::GetAtt: Lambda.Arn
ID: <see-below>
Lambda:
Type: AWS::Lambda::Function
Properties:
...
(where ID doesn't exist before the creation of CustomResource, but it needs to be populated by the result of Lambda upon creation)