在嵌入式python中使用cfnresponse创建自定义支持的云形成资源时出错

阿比奈

尝试使用cfnresponse创建内联python lambda函数作为自定义支持的cloudformation资源..以获取资源创建的信息。但是我的堆栈因错误而回滚。

错误:CustomResource属性错误:供应商响应中的对象arn:aws:cloudformation:us-west-2:stack / Custom-lambda / 8eaeead0-68b8-11e9-8e31-0247c451c136 | CustomResource | 3a7885fc-0959- S3存储桶cloudformation-custom-resource-storage-uswest2中的4284-b4f6-8153fe6420df。用户请求的回滚。

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "AWS CloudFormation to set up a custom CloudFormation resource with Lambda, and then call it in the same template.",
    "Resources": {
        "CustomFunction": {
            "Type": "AWS::Lambda::Function",
            "Properties": {
                "Code": {
                    "ZipFile": {
                        "Fn::Join": [
                            "\n",
                            [
                                "import urllib2",
                                "import os",
                                "import boto3",
                                "import json",
                                "import cfnresponse",
                                "def lambda_handler(event, context):",
                                "",
                                "    print 'EVENT ##################'",
                                "    print json.dumps(event)",
                                "    print '########################'",
                                "",
                                "    pid = 'optionalPhysicalID'",
                                "    response = {}",
                                "",
                                "    try:",
                                "",
                                "        response['Output'] = '-' + event['ResourceProperties']['Input'].upper() + '-'",
                                "",
                                "        if event['RequestType'] == 'Create':",
                                "            print 'Creating stack'",
                                "",
                                "        if event['RequestType'] == 'Update':",
                                "            print 'Updating Stack'",
                                "",
                                "        if event['RequestType'] == 'Delete':",
                                "            print 'Deleting Stack'",
                                "",
                                "    except Exception as e:",
                                "        print str(e)",
                                "        cfnresponse.send(event, context, cfnresponse.FAILED, { 'error': str(e) }, pid)",
                                "        return",
                                "",
                                "    cfnresponse.send(event, context, cfnresponse.SUCCESS, response, pid)",
                                "",
                                "    client = boto3.client('s3')",
                                "    response = urllib2.urlopen('https://s3-us-west-2.amazonaws.com/')",
                                "    html = response.read()",
                                "    filename = 'test.sh' ",
                                "    path ='/tmp/'+filename",
                                "    file_ = open(path, 'w')",
                                "    file_.write(html)",
                                "    file_.close()",
                                "    local_file_name = 'tmp/'+filename",
                                "    account_number =boto3.client('sts').get_caller_identity().get('Account')",
                                "    print(account_number)",
                                "    client.create_bucket(Bucket='abc-'+account_number+'-emr-files',",
                                "    CreateBucketConfiguration={'LocationConstraint': 'us-west-2'})",
                                "    client.put_object(Bucket='abc-'+account_number+'-emr-files',Key=filename)"
                            ]
                        ]
                    }
                },
                "Role": {
                    "Fn::Join": [
                        "",
                        [
                            "arn:aws:iam::",
                            {
                                "Ref": "AWS::AccountId"
                            },
                            ":role/AWS__AD_DNS_EMR_Clnup_Lambda_Exctn_Role"
                        ]
                    ]
                },
                "Handler": "index.lambda_handler",
                "MemorySize": "128",
                "Runtime": "python2.7",
                "Timeout": 180
            },
            "Metadata": {
                "AWS::CloudFormation::Designer": {
                    "id": "e683a5e0-d8e2-4747-84ed-3273acd09d66"
                }
            }
        },
        "CustomResource": {
            "Type": "Custom::CustomResource",
            "Properties": {
                "ServiceToken": {
                    "Fn::GetAtt": [
                        "CustomFunction",
                        "Arn"
                    ]
                },
                "Input": "Parameter to pass into Custom Lambda Function"
            },
            "Metadata": {
                "AWS::CloudFormation::Designer": {
                    "id": "2a474cb7-859c-4647-958e-c72674dd1a6b"
                }
            }
        }
    },
    "Outputs": {
        "Message": {
            "Description": "The message from the custom resource.",
            "Value": {
                "Fn::GetAtt": [
                    "CustomResource",
                    "Message"
                ]
            }
        },
        "CustomFunctionArn": {
            "Description": "The arn of the custom resource function.",
            "Value": {
                "Fn::GetAtt": [
                    "CustomFunction",
                    "Arn"
                ]
            }
        }
    },
    "Metadata": {
        "AWS::CloudFormation::Designer": {
            "e683a5e0-d8e2-4747-84ed-3273acd09d66": {
                "size": {
                    "width": 60,
                    "height": 60
                },
                "position": {
                    "x": 60,
                    "y": 90
                },
                "z": 1,
                "embeds": []
            },
            "2a474cb7-859c-4647-958e-c72674dd1a6b": {
                "size": {
                    "width": 60,
                    "height": 60
                },
                "position": {
                    "x": 180,
                    "y": 90
                },
                "z": 1,
                "embeds": []
            }
        }
    }
}
弗拉迪斯拉夫·乌申科

检查关键MessageOutputs部分。您正在使用内部函数GetAtt来获取Message来自的属性CustomResource出现的CloudFormation错误告诉我们该函数没有Message作为资源的返回值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用嵌入式Jetty设置静态资源和自定义服务?

如何使用注释代替XML在嵌入式Tomcat中创建自定义组件标签

如何使用vimeo嵌入式代码创建自定义的seekTo播放器界面?

尝试使用嵌入式JDK而非自定义安装时,Android Studio显示错误

如何在angular 6中使用自定义指令渲染动态生成的嵌入式SVG

在具有自定义通道绑定的Spring Cloud流测试中使用嵌入式Kafka

使用CEFPython为Chromium嵌入式框架定义自定义方案处理程序

进入嵌入式自定义界面

Swift:调整嵌入式自定义NSView的大小

嵌入式调查中的SurveyMonkey自定义变量

在AngularJS $ resource中使用嵌入式资源URL

在捆绑中使用嵌入式资源的ASP.NET

在 ngFor 中使用自定义管道时出错

使用自定义键创建KTable时出错

在python中使用resample('W'),sum()进行基于自定义期间的重采样时出错

创建自定义变量时出错

在routes.rb中使用自定义to_param的嵌套资源时,如何允许强参数创建/更新以允许?

使用自定义QT / X11应用程序作为桌面背景构建嵌入式设置

Telegram bot:如何使用嵌入式键盘发送消息并同时隐藏自定义键盘?

如何仅使用嵌入式CSS(用于电子邮件)自定义无序列表项目符号?

在具有嵌入式形式的自定义指令上使用ngModel,并具有有效的验证?

在路由中使用资源时在Controller中使用自定义功能-Laravel

在Django,Python中使用MongoEngine查询嵌入式文档

在Makefile中使用嵌入式python脚本

在 android Chrome 自定义选项卡中禁用嵌入式媒体

Spring Boot为嵌入式服务器配置自定义jsessionid

自定义对象拖动和下降,由嵌入式FX(JFXPanel)到Swing

嵌入式报表上的 Data Studio 自定义可视化

在网站中自定义Braintree嵌入式UI