gpt4 book ai didi

amazon-web-services - 将 CloudFormation 自定义 SNS 资源转换为 AWS CLI

转载 作者:行者123 更新时间:2023-12-03 07:44:34 25 4
gpt4 key购买 nike

我正在尝试将供应商提供的 CloudFormation Stack 转换为 Terraform。有一个用于发送 SNS 通知的 AWS::CloudFormation::CustomResource:

...
"RegistrationNotification": {
"Type": "AWS::CloudFormation::CustomResource",
"Version": "1.0",
"Properties": {
"ServiceToken": {"Ref" : "SnsTopicRegistration"},
"Version": "1.0",
"AccountID": {
"Ref": "AWS::AccountId"
},
"CloudTrailCreated": {
"Ref": "EnableNewCloudTrail"
},
"IamRoleARN": {
"Fn::GetAtt": [
"iamRole",
"Arn"
]
}
}
}
...

我的计划是为 aws snspublish 提供本地执行资源。但是,自定义资源属性是作为消息属性发送还是在消息正文中发送?

这是我迄今为止尝试过的方法,但我不相信它有效。

message.txt:
{
"AccountID":"111111111111",
"CloudTrailCreated":"false",
"IAMRoleArn":"arn:aws:iam::111111111111:role/TestRole"
}

aws sns publish --target-arn "arn:aws:sns:us-west-2:123456789012:test-topic" --message file://message.txt

最佳答案

设置我自己的 SNS->SQS 管道并覆盖供应商的 SNS 目标后,我能够看到 CloudFormation 生成的完整消息:

message.txt: 
{
"RequestType":"Create",
"ServiceToken":"arn:aws:sns:us-east-1:999999999999:registration",
"ResponseURL":"https://custom-resource-response-useast1.s3-us-east-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aus-east-1%3A111111111111%3Astack/Vendor_App/f16ba060-f981-11e8%7CRegistrationNotification%7C754d1dbc-2cc9-4b5f-855a?AWSAccessKeyId=AKIAIBLSGNTMEXAMPLE&Expires=1544126938&Signature=UohvGFPBHWrCz%2BMxgVKHF1L%2FNe4%3D",
"StackId":"arn:aws:cloudformation:us-east-1:111111111111:stack/Vendor_App/f16ba060-f981-11e8-9ecc",
"RequestId":"754d1dbc-2cc9-4b5f-855a",
"LogicalResourceId":"RegistrationNotification",
"ResourceType":"AWS::CloudFormation::CustomResource",
"ResourceProperties":{
"ServiceToken":"arn:aws:sns:us-east-1:999999999999:cs-cloudconnect-manager-registration",
"AccountID":"111111111111",
"Version":"1.0",
"IamRoleARN":"arn:aws:iam::111111111111:role/TestRole",
"CloudTrailCreated":"false"
}
}

AWS CloudFormation Custom Resource Request Objects文档有助于了解哪些字段是必填字段。

最终,我使用本地执行资源的计划失败了,我只好从 Terraform 调用 CloudFormation Stack:

resource "aws_cloudformation_stack" "vendor-stack" {
name = "Vendor-App-Stack"
capabilities = [ "CAPABILITY_NAMED_IAM" ]
parameters {
RoleName="TestRole"
EnableNewCloudTrail="false"
}
template_url = "https://s3.amazonaws.com/vendor-prod-templates/aws_cloudformation_v1.0.json"
}

关于amazon-web-services - 将 CloudFormation 自定义 SNS 资源转换为 AWS CLI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53654974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com