无法使用 CloudFormation 将代码添加到 AWS Lambda 函数
Cannot add code to AWS Lambda function using CloudFormation
我正在尝试创建 Cloud Formation Stack。堆栈已正确部署。 Lambda 函数已创建,但代码未作为内联添加到函数中。
它说
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
。
If you specify your source code as inline text by specifying the ZipFile property within the Code property, specify index.function_name as the handler.
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
。
我正在尝试创建 Cloud Formation Stack。堆栈已正确部署。 Lambda 函数已创建,但代码未作为内联添加到函数中。
它说
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
。
If you specify your source code as inline text by specifying the ZipFile property within the Code property, specify index.function_name as the handler. 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
。