在我的AWS Lambda函数中使用查询字符串值

时间:2016-02-19 15:06:28

标签: python amazon-web-services lambda

所以我从另一个堆栈问题中跟踪了这个gudie:

实现这一目标的步骤是:

  1. 转到资源 - >集成请求
  2. 点击模板下拉列表旁边的加号或编辑图标(奇怪我知道,因为模板字段已经打开,此处的按钮看起来是灰色的)
  3. 在内容类型字段中显式输入application / json,即使它显示默认值(如果你不这样做,它也不会保存,也不会给你一个错误信息)
  4. 将其放入输入映射{“name”:“$ input.params('name')”}
  5. 点击模板下拉框旁边的复选框(我假设这是最终保存的内容)
  6. 我理解这一点但是我不明白如何在我的lambda函数(Python)中使用这个参数

    我尝试过input.name但没有成功。

1 个答案:

答案 0 :(得分:0)

您可以使用如下查询字符串:

UserName = event["UserName"] 

这是Python的一个例子:

def lambda_handler(event, context):
import boto3
import json
import decimal

# Helper class to convert a DynamoDB item to JSON.
class DecimalEncoder(json.JSONEncoder):
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            if o % 1 > 0:
                return float(o)
            else:
                return int(o)
        return super(DecimalEncoder, self).default(o)

dynamodb = boto3.resource('dynamodb', region_name='ap-southeast-1', endpoint_url="http://dynamodb.ap-southeast-1.amazonaws.com")
table = dynamodb.Table('TableUsers')

UserName =event["UserName"]
UserId = event["UserId"]
UserPassword=event["UserPassword"]

response = table.put_item(
   Item={
        'UserName': UserName,
        'UserId': UserId,
        'UserPassword':UserPassword
    }
)
return "Register Successfully"