如何存储从 cloudformation 堆栈输入的参数?

How to store the entered parameters from cloudformation stack?

我想要完成的是从 Cloudformation 堆栈存储输入的参数。

例如: 假设有两个参数 param1param2

我想将输入的值存储在 DynamoDB、RDS Db 等中

我虽然在 SNS 通知中:

不幸的是,通知的负载如下所示:

StackId='arn:aws:cloudformation:us-east-1:accountId:stack/rfdsf/b6df0100-fd18-11e7-b3ab-500c2893c0d2'
Timestamp='2018-01-19T13:00:24.774Z'
EventId='b6df9d40-fd18-11e7-b3ab-500c2893c0d2'
LogicalResourceId='rfdsf'
Namespace='accountId'
PhysicalResourceId='arn:aws:cloudformation:us-east-1:accountId:stack/rfdsf/b6df0100-fd18-11e7-b3ab-500c2893c0d2'
PrincipalId='accountId'
ResourceProperties='null'
ResourceStatus='CREATE_IN_PROGRESS'
ResourceStatusReason='User Initiated'
ResourceType='AWS::CloudFormation::Stack'
StackName='rfdsf'
ClientRequestToken='Console-CreateStack-774eec95-c976-434c-b43b-ad3d295a0b9b'

如您所见,没有任何输入值。

是否可以将输入的参数存储到数据库中?

根据@Rodrigigo M 的建议,您可以将参数保存到 SSM 参数存储中。

Description: "Create SSM Parameter"
Resources:
  BasicParameter:
    Type: "AWS::SSM::Parameter"
    Properties:
      Name: "param1"
      Type: "String"
      Value: "ABCD"
      Description: "SSM Parameter for running date command."
      AllowedPattern: "^[a-zA-Z]{1,10}$"

此外,如果您想将这些保存到数据库中,您可以创建一个 Lambda 来读取它们并存储到 DynamoDb 或 RDS 中。

在您的 cloudformation 中有一个 Outputs 参数。只要明确指定要输出的参数,就可以输出进入堆栈的任何值。

这些值将在 cloudformation 的“输出”选项卡中可见。如果您想将它们移动到数据库,例如 DynamoDB,您可以使用 cloudformation:describeStacks api 调用来获取任何堆栈的所有输出值。