我正在创建一个 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 Resource 的 ServiceToken
参数。请参阅 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/