PATCH method with Lambda integration for update operation on unknown number of parameters

我与影子孤独终老i 提交于 2020-08-10 19:17:24

问题


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

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 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.

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.

Table has 10 column ID being the primary key.

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?


回答1:


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.

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.

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).

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.



来源:https://stackoverflow.com/questions/63117159/patch-method-with-lambda-integration-for-update-operation-on-unknown-number-of-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!