AWS Lambda(一)---创建一个lamda函数

1. 在aws cloud首页搜索 lamda,进入到lamda创建function的页面

https://console.aws.amazon.com/lambda/home?region=us-east-1#/create/function

2.选择或创建role

在步骤1的界面里面的basic information里,依次填写function name 为 hello,runtime选择 python,choose or create an execution role选择现有的role,如果没有现有的role,点击IAM role新建一个,如下图

3. 创建function

点击页面底部的 create function按钮,到了下面这一页:

其中lambda_function区域的代码如下:

import json

print('Loading your function')

def lambda_handler(event, context):
    print("message --> " + event['message'])

    return event['message']
    raise Exception('Something went wrong!')

4. 点击页面上方的 select a test event的下拉框,选择config test event, 填写event name和相应的测试入参,点击create按钮。

图中红框的内容如下:

{
  "message": "Congrats! Your first successful Lambda function! Oh....and 'Hello World!' ",
  "notmessage": "If this shows, it is broken!"
}

5. 步骤4完毕后,会跳转到lambda页面,点击上方的save按钮,再点击test按钮,可以得到测试结果

发布了140 篇原创文章 · 获赞 80 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/daiqinge/article/details/103283484
AWS