无法使用CloudFormation将代码添加到AWS Lambda函数 [英] Cannot add code to AWS Lambda function using CloudFormation
问题描述
我正在尝试创建云形成堆栈。堆叠部署正确。 Lambda函数已创建,但未将代码作为内联函数添加到函数中。
I'm trying to create the Cloud Formation Stack. The Stack was deployed correctly. Lambda function was created, but the code is not getting added as inline to the function.
它表示
您的Lambda函数 lambda_function无法内联编辑,因为处理程序中指定的文件名与您的部署包中的文件名不匹配。
Your Lambda function "lambda_function" cannot be edited inline since the file name specified in the handler does not match a file name in your deployment package.
云形成代码:
LambdaFunction:
Type: "AWS::Lambda::Function"
Properties:
Code:
ZipFile: !Sub |
import json
def lambda_handler(event,context):
#Creating delete request
...
Description: Lambda function.
FunctionName: lambda_function
Handler: lambda_function.lambda_handler
Role : !GetAtt LambdaExecutionRole.Arn
Runtime: python2.7
Timeout: 5
推荐答案
处理程序的第一部分应始终为 index
如果您指定代码为内联。
The first part of the handler should always be index
if you specify the code inline.
如果您通过在代码中指定ZipFile属性将源代码指定为内联文本代码属性,将index.function_name指定为处理程序。
http://docs.aws .amazon.com / AWSCloudFormation / latest / UserGuide / aws-resource-lambda-function.html
所以只需使用此:
LambdaFunction:
Type: "AWS::Lambda::Function"
Properties:
Code:
ZipFile: !Sub |
import json
def lambda_handler(event,context):
#Creating delete request
...
Description: Lambda function.
FunctionName: lambda_function
Handler: index.lambda_handler
Role : !GetAtt LambdaExecutionRole.Arn
Runtime: python2.7
Timeout: 5
注意 index.lambda_handler
而不是 lambda_function.lambda_handler
。
这篇关于无法使用CloudFormation将代码添加到AWS Lambda函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!