我正在尝试在CloudFormation模板中学习CustomResources的工作。创建简单模板以创建s3存储桶。但是在创建堆栈时,它会长时间保持在“正在进行中”状态,并且不会创建任何存储桶。 有什么,我在以下经过验证的模板中遗漏了:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Building A bucket With customeResources in CloudFormation",
"Parameters" : {
"NewBucket": {
"Default": "",
"Description": "S3 bucket containing customer assets",
"Type": "String"
}
},
"Conditions": {
"NewBucket": {
"Fn::Not": [
{
"Fn::Equals": [
{
"Ref": "NewBucket"
},
""
]
}
]
}
},
"Resources" : {
"CustomResource": {
"Properties": {
"S3Bucket": {
"Ref": "NewBucket"
},
"ServiceToken": "SNS topic ARN"
},
"Type": "AWS::CloudFormation::CustomResource"
}
},
"Outputs": {
"BucketName": {
"Value": {
"Fn::GetAtt": [ "CustomResource", {"Ref": "NewBucket"} ]
}
}
}
}
答案 0 :(得分:1)
看来你的SNS支持的自定义资源没有将响应发送回云端,并且等待响应的时间一直存在。
来自Amazon Simple Notification Service-backed Custom Resources:
自定义资源提供程序处理模板发送的数据 开发人员并确定Create请求是否成功。 然后,资源提供程序使用AWS CloudFormation发送的S3 URL 发送SUCCESS或FAILED的回复。
当向SNS服务提供商发出请求时,它包含以下对象:
{
"RequestType": "Create",
"ServiceToken": "arn:aws:sns:us-west-2:2342342342:Critical-Alerts-development",
"ResponseURL": "https:\/\/cloudformation-custom-resource-response-uswest2.s3-us-west-2.amazonaws.com\/arn%3Aaws%3Acloudformation%3Aus-west-2%3A497903502641%3Astack\/custom-resource\/6bf07a80-d44a-11e7-84df-503aca41a029%7CCustomResource%7C5a695f41-61d7-475b-9110-cdbaec04ee55?AWSAccessKeyId=AKIAI4KYMPPRGIACET5Q&Expires=1511887381&Signature=WmHQVqIDCBwQSfcBMpzTfiWHz9I%3D",
"StackId": "arn:aws:cloudformation:us-west-2:asdasdasd:stack\/custom-resource\/6bf07a80-d44a-11e7-84df-503aca41a029",
"RequestId": "5a695f41-61d7-475b-9110-cdbaec04ee55",
"LogicalResourceId": "CustomResource",
"ResourceType": "AWS::CloudFormation::CustomResource",
"ResourceProperties": {
"ServiceToken": "arn:aws:sns:us-west-2:234234234:Critical-Alerts-development",
"S3Bucket": "test-example-com"
}
}
您需要向Cloud Formation事件中提供的ResponseURL
发送成功/失败响应以继续处理。
我还要注意,除非您的自定义服务提供商创建了该存储桶,否则不会创建该存储桶。自定义资源功能仅将请求发送给提供者。