【发布时间】: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