在堆栈更新时保留输出

时间:2020-01-30 11:04:53

标签: amazon-web-services aws-lambda amazon-cloudformation

我编写了一个Cloudformation模板,该模板使用DynamoDB表创建堆栈:

     "FeedStageDynamoTable" : {
        "Type" : "AWS::DynamoDB::Table",
        "UpdateReplacePolicy" : "Retain",
        "Properties" : {
            "TableName" : { "Fn::Sub": [ "feed-${Year}-${Environment}-table", { "Year": {"Ref" : "BundleYear" }, "Environment" : {"Ref" : "DeployEnvironment"}} ]},
            "AttributeDefinitions" : [
              {"AttributeName" : "Guid", "AttributeType" : "S"}
            ],
            "KeySchema"            : [
              {"AttributeName" : "Guid", "KeyType" : "HASH"}
            ],
            "ProvisionedThroughput" : {
                "ReadCapacityUnits" : "2",
                "WriteCapacityUnits" : "2"
            },
            "StreamSpecification": {
                "StreamViewType": "NEW_AND_OLD_IMAGES"
                }
        }
    }

和表流的输出:

"Outputs" : {
    "FeedStageTableStreamArn": {
        "Description" : "The security group ID to use for public web servers",
        "Value" :  { "Fn::GetAtt" : ["FeedStageDynamoTable", "StreamArn"] },
        "Export" : { "Name" : {"Fn::Sub": "${AWS::StackName}-FeedStageDynamoTableStreamArn" }}
    },

lambda函数从另一个模板(用于第二个堆栈)使用输出:

    "NotifyWebConsumer" : {
        "Type" : "AWS::Serverless::Function",
        "Properties": {
            "Environment": {
            "Variables" :  {
                "EnvironmentCodename" :  { "Fn::Sub": [ "${Environment}", { "Environment" : {"Ref" : "DeployEnvironment"}} ]}
                }
            },
            "Handler": "AmazonServerlessStageWebUpdate::AmazonServerlessStageWebUpdate.Functions::NotifyWebConsumer",
            "FunctionName": "NotifyWebConsumer",
            "Runtime": "dotnetcore2.1",
            "CodeUri": "",
            "MemorySize": 256,
            "Timeout": 30,
            "Policies":[{  "Fn::ImportValue" : {"Fn::Sub" : "${DeployEnvironment}-LambdaExecutionPolicy"} }],
            "Role":{"Fn::GetAtt": ["NotifyConsumerRole","Arn"]},
            "Events": {

            }
        }
    }

...

"EventSourceMapping": {
            "Type": "AWS::Lambda::EventSourceMapping",
            "Properties": {
             "EventSourceArn": {  "Fn::ImportValue" : {"Fn::Sub" : "StageEnvironment-FeedStageDynamoTableStreamArn"} },
              "FunctionName" : {
                    "Fn::GetAtt": [
                        "NotifyWebConsumer", "Arn"
                    ]
        },
              "StartingPosition" : "LATEST"
              }
        }

发布两个堆栈之后,我无法再更新第一个堆栈,因为第二个堆栈正在使用输出流。现在我的问题是:是否有cloudformation属性,例如“ UpdateReplacePolicy”:输出的“ Retain”?还是有其他方法可以在不删除第二个堆栈的情况下更新第一个堆栈?

0 个答案:

没有答案