如何在Python中创建简单的lambda函数
这似乎是NodeJS的示例,但正在寻找Python版本。
aws lambda create-function --function-name helloworld \
--zip-file fileb://function.zip --handler index.handler --runtime nodejs8.10 \
--role arn:aws:iam::123456789012:role/lambda-cli-role
{
"FunctionName": "helloworld",
"CodeSize": 351,
"MemorySize": 128,
"FunctionArn": "function-arn",
"Handler": "index.handler",
"Role": "arn:aws:iam::account-id:role/LambdaExecRole",
"Timeout": 3,
"LastModified": "2015-04-07T22:02:58.854+0000",
"Runtime": "nodejs8.10",
"Description": ""
}
答案 0 :(得分:2)
您可以使用相同的CLI选项,但可以指定python运行时以及以zip文件格式包含python应用程序。
aws lambda create-function --function-name helloworld \
--zip-file fileb://test.zip \
--handler lambda_function.lambda_handler \
--runtime python3.7 \
--role arn:aws:iam::XXXX:role/CustomLambdaRoleARN
CLI Output:
{
"FunctionName": "helloworld",
"FunctionArn": "arn:aws:lambda:us-west-2:XXXXXX:function:helloworld",
"Runtime": "python3.7",
"Role": "arn:aws:iam::XXXX:role/CustomLambdaRoleARN",
"Handler": "lambda_function.lambda_handler",
"CodeSize": 236,
"Description": "",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2019-04-23T04:25:33.052+0000",
"CodeSha256": "5Gm3xdLGxELEIboaATKL7pr4sxrjNV1kuT9l9kpFG0g=",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "3f18add5-d347-4754-83e5-61dfdeabda9a"
如果您需要构建Lambda应用程序zip文件的帮助,请参阅此演练。 https://geektopia.tech/post.php?blogpost=Create_Lambda_Package_Python