2
votes

I have a CF template with a custom resource (backed by a lambda function).

I would like this custom resource to be deleted and the newly created when I update my stack. How can I achieve this?

To make this practical, let's assume I have a custom resource which simply produces a random string.
More or less as described here:

https://www.itonaut.com/2018/01/03/generate-passwords-in-aws-cloudformation-template/

So I have a resource like:

  RandomSuffix:
    Type: AWS::CloudFormation::CustomResource
    DeletionPolicy: Delete
    Properties:
      Length: 3
      ServiceToken: !ImportValue
        'Fn::Sub': 'cf-utils-RandomStringFunction-Arn'

In general, this works, I get some random string as RandomSuffix.Value.

However, after an update, this values stays the same.

Is there any way to force deletion and recreation of my custom resource during update?

1

1 Answers

1
votes

You need to change it's name. e.g. RandomSuffix=>RandomSuffix20191210