【问题标题】:Custom::LambdaTrigger resource is stuck at CREATE_IN_PROGRESS while using Cloud FormationCustom::LambdaTrigger 资源在使用 Cloud Formation 时卡在 CREATE_IN_PROGRESS
【发布时间】:2019-11-30 08:46:24
【问题描述】:

我正在尝试使用 AWS Cloud Formation 创建堆栈。我有一个导致问题的 Custom::LambdaTrigger 资源。

资源卡在 CREATE_IN_PROGRESS 很长时间。参考下图:

按照对应的成云代码:

 "ApiDeployerTrigger": {
            "Type": "Custom::LambdaTrigger",
            "Properties": {
                "ServiceToken": {
                    "Fn::GetAtt": [
                        "ApiDeployer",
                        "Arn"
                    ]
                },
                "RestApiId": {
                    "Ref": "ApiGateway"
                },
                "StageName": "v1",
                "SeqNo": {
                    "Ref": "PackageVersion"
                }
            },
            "DependsOn": [
                "ApiGateway"
            ]
        }

然后,它创建失败并发生回滚。

然后回滚也失败了

更新: 我查看了 CloudWatch 日志。我收到以下错误:

以下是创建 lambda 函数的代码:

        "ApiDeployer": {
            "Properties": {
                "Code": {
                    "ZipFile": {
                        "Fn::Join": [
                            "\n", [
                                "var aws = require('aws-sdk');",
                                "var response = require('cfn-response');",
                                "exports.handler = function(event, context, callback){",
                                "console.log(event);",
                                "try{",
                                " var apigateway = new aws.APIGateway();",
                                " if (event.RequestType == 'Update' || event.RequestType == 'Create'){",
                                "   var params = {};",
                                "   params.restApiId = event.ResourceProperties.RestApiId;",
                                "   params.stageName = event.ResourceProperties.StageName;",
                                "   apigateway.createDeployment(params, function(err, data) {",
                                "   if (err){",
                                "     console.log(err);",
                                "     response.send(event, context, response.FAILED, err);",
                                "     callback(null);",
                                "   }else {",
                                "     console.log(data);",
                                "     var id = event.PhysicalResourceId ? event.PhysicalResourceId : 'Deployment'+new Date().toISOString().replace(/[-T\\:.Z]/ig,'');",
                                "     response.send(event, context, response.SUCCESS, data, id);",
                                "     callback(null, 'Deployed API');",
                                "    }",
                                "   });",
                                " }else{",
                                "  response.send(event, context, response.SUCCESS, {}, event.PhysicalResourceId);",
                                "  allback(null);",
                                " }",
                                "} catch(e) {",
                                "  console.log(e);",
                                "  response.send(event, context, response.FAILED, e);",
                                "  callback(null);",
                                "}",
                                "};"
                            ]
                        ]
                    }
                },
                "Handler": "index.handler",
                "Role": {
                    "Fn::GetAtt": [
                        "ApiLambdaExecutionRole",
                        "Arn"
                    ]
                },
                "Runtime": "nodejs10.x",
                "Timeout": 60
            },
            "Type": "AWS::Lambda::Function"
        }

任何线索,有什么问题?

【问题讨论】:

    标签: amazon-web-services aws-lambda amazon-cloudformation


    【解决方案1】:

    似乎是 lamda 运行时 nodejs10.x 的问题。

    找不到 cfn-response 模块。

    var response = require('cfn-response') 更改为var response = require('./cfn-response') 解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-29
      • 2021-10-24
      • 2020-07-11
      • 2021-10-18
      • 2021-01-06
      • 2018-09-15
      • 1970-01-01
      • 2020-11-04
      相关资源
      最近更新 更多