具有Lambda集成的PATCH方法,可对未知数量的参数进行更新操作 [英] PATCH method with Lambda integration for update operation on unknown number of parameters

查看:95
本文介绍了具有Lambda集成的PATCH方法,可对未知数量的参数进行更新操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过API网关使用PATCH方法创建了资源,并将其与Lambda集成在一起,并且还集成了代理.

I have created a resource with PATCH method through API Gateway and have it integrated with Lambda and also have integrated proxy on it.

我已经对方案进行了硬编码以更新表. lambda函数的小片段

I have hard coded the scenario to update the table. small snippet from the lambda function

def lambda_handler(event, context):
    # reading query parameters to work on from api end point 
    supplierID = event['queryStringParameters']['supplierID']
    supplierName = event['queryStringParameters']['supplierName']

supplierID是表的主键,我正在尝试从表中更新SupplierName.

supplierID is the primary key of the table and i am trying to update the supplierName from the table.

在上述情况下,我知道在尝试测试工作时必须更新的内容.

In this above scenario i know what i have to update as i was trying to test the working.

现在,我想知道当我不知道要从api请求的查询参数中获取哪个文件进行更新时该怎么做.

Now i am wondering how can i do it when i don't know which filed i will get from the query parameter of the api request to update.

表有10个列ID作为主键.

Table has 10 column ID being the primary key.

如何存储未知的查询参数并在Postgresql RDS上进行更新.

How can i store the unknown query parameter and operate a update on Postgresql RDS.

还是我应该使用其他任何方法来实现这一目标?

Or should i use any other method to achieve this?

推荐答案

如果您具有预定义数量的查询字符串参数,则可以创建一个映射函数来转换/处理event['queryStringParameters']中的参数,以确定它们将映射到哪一列

IF you have a predefined number of query string parameters you could create a mapping function to convert/process the parameters inside event['queryStringParameters'] to determine which column they would map to.

您需要设置一个必填字段,该字段必须唯一并且可以进行更新,如果未指定ID,则会向用户返回错误.

You would need to set a mandatory field which must be unique and would allow an update, if the ID was not specified you would return an error to the user.

如果这是未知的查询字符串参数,则无需将其存储在数据库中.而是向用户返回一条消息并写入您的日志( CloudWatch日志(以JSON格式).如果您以JSON格式输出,则可以使用 CloudWatch日志见解查看事件(甚至设置警报).

If this is an unknown query string parameter there is no need to store it in your database. Instead return a message to the user and write to your log (CloudWatch logs in JSON format). If you output in a JSON format you can then report using CloudWatch logs insights to view occurrences (and even set an alarm).

在旁注中,由于这是更新,因此优先使用带有查询字符串参数的PUT请求而不是GET请求.尤其是在信息可能敏感的情况下.

On a sidenote, as this is an update it would preferential to use a PUT request not a GET request with query string parameters. Especially if the information might be sensitive.

这篇关于具有Lambda集成的PATCH方法,可对未知数量的参数进行更新操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆