CloudFormation - update-stack deletes existing GG component versions

1

Hello,

Is there a way to use CloudFormation to create new versions of a Greengrass component without deleting older ones?

My intent is to prove this out in CloudFormation, then migrate to CDK and make an L2 construct for our use.

I'm migrating from direct manipulation of Greengrass resources to CloudFormation. This includes creation and deployment of custom components. When I call update-stack to create a new Greengrass component version, it deletes any other existing versions. Is there a way to use CDK and retain older component versions? Preferably this would be without having to rename the component each time, or place a permissions override on the delete. I have tried adding the retain flag to the resource. Here is the template I'm using:

Parameters:
  ComponentVersion:
    Type: String
Resources:
  MyComponentVersion:
    Type: AWS::GreengrassV2::ComponentVersion
    DeletionPolicy: Retain
    Properties:
      InlineRecipe: !Sub
        - "{\n
          \"RecipeFormatVersion\": \"2020-01-25\",\n
          \"ComponentName\": \"com.me.cftestapp\",\n
          \"ComponentVersion\": \"${ComponentVersion}\",\n
          \"ComponentType\": \"aws.greengrass.generic\",\n
          \"ComponentDescription\": \"Test CF usage\",\n
          \"ComponentPublisher\": \"me\",\n
          \"ComponentConfiguration\": {\n
            \"DefaultConfiguration\": {\n
              \"accessControl\": {\n
                \"aws.greengrass.ipc.mqttproxy\": {\n
                  \"com.example.MyIoTCorePubSubComponent:mqttproxy:1\": {\n
                    \"policyDescription\": \"Allows access to publish/subscribe to all topics.\",\n
                    \"operations\": [\n
                      \"aws.greengrass#PublishToIoTCore\",\n
                      \"aws.greengrass#SubscribeToIoTCore\"\n
                    ],\n
                    \"resources\": [\n
                      \"*\"\n
                    ]\n
                  }\n
                },\n
                \"aws.greengrass.ipc.pubsub\": {\n
                  \"com.example.MyLocalPubSubComponent:pubsub:1\": {\n
                    \"policyDescription\": \"Allows access to publish/subscribe to all topics.\",\n
                    \"operations\": [\n
                      \"aws.greengrass#PublishToTopic\",\n
                      \"aws.greengrass#SubscribeToTopic\"\n
                    ],\n
                    \"resources\": [\n
                      \"*\"\n
                    ]\n
                  }\n
                }\n
              }\n
            }\n
          },\n
          \"Manifests\": [\n
            {\n
              \"Platform\": {\n
                \"os\": \"linux\",\n
                \"architecture\": \"amd64\"\n
              },\n
              \"Name\": \"cf-test-amd64-linux\",\n
              \"Lifecycle\": {\n
                \"run\": \"{artifacts:path}/hello-world.sh\"\n
              },\n
              \"Artifacts\": [\n
                {\n
                  \"Uri\": \"s3://mys3/hello-world.sh\",\n
                  \"Digest\": \"clBq/9HjX5aGmU3+wJY/pRlM+DCDOKaXRTSR1svdqMA=\",\n
                  \"Algorithm\": \"SHA-256\",\n
                  \"Unarchive\": \"NONE\",\n
                  \"Permission\": {\n
                    \"Read\": \"OWNER\",\n
                    \"Execute\": \"ALL\"\n
                  }\n
                }\n
              ]\n
            }\n
          ],\n
          \"Lifecycle\": {\n
          }\n
        }"
        - { ComponentVersion: !Ref ComponentVersion }
1 Answer
2
Accepted Answer

During replacement update, usually CloudFormation will create new resource first and then deletes old resource during cleanup phase. So, in case of Green Grass component versions replacement, it creates new version and then deletes old version.

In order to retain older version, we usually suggest to use UpdateReplacePolicy: Retain [1] attribute in the template, So that, older version will be retained. Please refer the document [1] for examples

If you face same issue, even after using this attribute, you can reach out to AWS Support [2], as the support engineers have the necessary permissions to check the CloudFormation stack in your account.

REFERENCES:

[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html

[2] https://aws.amazon.com/contact-us/

AWS
SUPPORT ENGINEER
answered 2 months ago
profile picture
EXPERT
reviewed a month ago
  • That worked great! Thank you!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions