amazon-web-services - CloudFormation 自定义资源响应键

标签 amazon-web-services lambda aws-cloudformation devops infrastructure-as-code

我在 CloudFormation 中有 lambda 支持的自定义堆栈,所以我需要获取函数输出并将其放入 AWS 控制台,我该如何处理这个问题?

我的堆栈如下所示;

     "CreateExistingVPC": {
  "Type": "Custom::CreateExistingVPC",
  "Properties": {
    "ServiceToken": { "Fn::If": ["LambdaAvailable",{ "Fn::GetAtt": [ "CustomLogic", "Outputs.LambdaAttachHostedZoneArn" ] }, { "Ref": "AWS::NoValue" } ] },
    "Region": { "Ref": "AWS::Region" },
    "HostedZoneId": { "Ref": "InternalHostedZone" },
    "VpcId": { "Fn::GetAtt": [ "VPC", "Outputs.VPC" ] }
  }
}
},

  "Outputs": {
  "Route53VPC": {
  "Description": "ExistingRoute53VPCStatus",
  "Value": { "Fn::GetAtt": [ "CreateExistingVPC", "{ ??????? }" ] }
}
}

实际上,我已经找到了一些答案,但“响应键”在我的情况下不起作用,我如何找到响应键?

AWS Cloudformation, Output value from Custom Resource

最佳答案

您需要使用您正在使用的变量来返回您的响应。例如(nodeJs)

module.exports.createPoolList = (event, context, callback) => {

  if (event.RequestType == 'Create') {
    let array = event.ResourceProperties.OpsPoolArnList.split(",");

    array.push(event.ResourceProperties.UserPool);

    let response = {
        'list': array.join(),
    };

    sendresponse(event, "SUCCESS", response, "");
  }

  if (event.RequestType == 'Delete') {
      sendresponse(event, "SUCCESS", null, "");
  }

  callback(null, "");
};

这里list是包含我的输出并在我的响应中返回的变量。构建的有效负载如下所示

let payload = {
    'StackId': event.StackId,
    'Status' : responsestatus,
    'Reason' : reason,
    'RequestId': event.RequestId,
    'LogicalResourceId': event.LogicalResourceId,
    'PhysicalResourceId': event.LogicalResourceId + 'qwerty',
    'Data': response
};

我在脚本中将其称为

!GetAtt <ResourceName>.list

希望有帮助。

关于amazon-web-services - CloudFormation 自定义资源响应键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55117634/

相关文章:

amazon-web-services - Logstash无法将日志推送到ES

amazon-web-services - 在进行应用程序开发时,我可以使用 "aws-toolkit for VSCode"安全地保存我的凭据吗?

c++ - 在模板化类与非模板化类中的 lambda 属性中捕获它

amazon-web-services - 使用参数在 AWS SAM 中动态创建资源名称

amazon-web-services - 云形成策略生成不正确

mysql - 使用 Sequel Pro 连接到 AWS Aurora MySQL

amazon-web-services - 在 Elastic Beanstalk 上安装 Tesseract 的最快方法

c++ - 将 lambda 作为构造函数参数传递

c++ - 无法将 std::set_intersection 应用于具有公共(public)字段的不同类型的结构

amazon-web-services - boto CloudFormation BadRequest (400),异常 : None