json - 使用customResource将RDS层注册到opsworks堆栈

标签 json aws-opsworks aws-cloudformation

我正在创建一个 cloudformation 模板,用于创建堆栈、层和应用程序。应用程序的数据库配置为 Datasources :

"AdminApp": {
      "Type": "AWS::OpsWorks::App",
      "Properties": {
        "AppSource" : {
          "Type" : "git",
          "Url" : "git://github.com:myrepo/adminapp.git",
          "Revision" : "master"
        },
        "DataSources":[{
          "Arn" : { "Ref" : "RegisterRDStoStack" },
          "DatabaseName" : "fadmin",
          "Type" : "RdsDbInstance"
        }],
        "Description": "Administration",
        "Name" : "admin-api",
        "Shortname" : "admin_api",
        "StackId" : {"Ref": "Stack"},
        "Type" : "php"
      }
    },

属性Datasources中的数据库应首先注册到堆栈中,以便应用程序可以访问它。 由于 AWS 尚未使用 Cloudformation 在 opsworks 堆栈中实现 RDS 层的创建,因此我创建了一个 CustomResource 作为解决方法:

"RegisterRDStoStack" : {
  "Type": "Custom::RDSLayer",
  "Version" : "1.0",
  "Properties" : {
    "ServiceToken": {"Ref" : "RDSInstanceARN"},
    "StackId" : {"Ref" : "Stack" },
    "User" : {"Ref" : "UserDB" },
    "Password" : {"Ref" : "PasswordDB" }
  }
},

测试模板时出现此错误:

CREATE_FAILED   Custom::RDSLayer    RegisterRDStoStack  Invalid service token

看来是有错误,但不知 Prop 体是什么。我正确提供了数据库的 ARN。请问我应该做什么才能使这项工作正常进行?有什么想法吗?

最佳答案

您需要提供 Lambda 函数的 ARN(例如 {"Ref": "MyLambdaFunction"})作为 Custom ResourceServiceToken 参数。请参阅 ServiceToken 的文档:

The service token that was given to the template developer by the service provider to access the service, such as an Amazon SNS topic ARN or Lambda function ARN. The service token must be from the same region in which you are creating the stack.

关于json - 使用customResource将RDS层注册到opsworks堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41874463/

相关文章:

jenkins - 持续集成 : running Jenkins Build on newly created EC2 Instance using AWS Cloudformation+OpsWorks, 什么是最佳实践?

javascript - 使用 AWS OpsWorks 以具有 sudo 权限的用户身份运行 `before_migrate.rb` 中的命令

aws-cloudformation - 向堆栈添加权限边界

javascript - 使用 for 循环创建 json 感到困惑

javascript - manifest.json 的问题

javascript - 如何使用用户输入通过iron-ajax发出REST请求

python - 操作json文件python

ruby - 厨师属性 "no implicit conversion of String into Integer"

amazon-web-services - 无法验证以下目标配置((服务 : Amazon S3; Status Code: 400; Error Code: InvalidArgument)

amazon-web-services - 使用 Cloudformation 将多个 BlockDeviceMappings 安装到 EC2 实例