scar icon indicating copy to clipboard operation
scar copied to clipboard

How do I send an input(for ex a json input) to my script that is running in the container in aws lambda?

Open swarnim-cn opened this issue 4 years ago • 3 comments

I can see that we can send an input "file" either through S3 or using the -db flag but I am not sure how to send an input like a json object to the script file. Is there any example using this?

swarnim-cn avatar Jun 23 '20 12:06 swarnim-cn

Hi @swarnim-cn, thank you for using SCAR, you can send a JSON object through API Gateway by sending it in the GET body. SCAR automatically saves the body as a file that will be reachable from the INPUT_FILE_PATH in the script.

To store results you can create a new file in the TMP_OUTPUT_DIR that will be uploaded to your configured S3 output bucket or, if you want to get the result directly from the HTTP request, you can simply do a cat /result/file in your script, but remember the limitations and that the result will be encoded in base64. Documentation will be updated soon to clarify these use cases.

I hope I've been helpful. I would appreciate if you could provide me some information about the use case you want to run with SCAR, as this project is part of my doctoral thesis and I need to collect information about its usage.

Regards.

srisco avatar Jun 23 '20 14:06 srisco

Hi @srisco

I have mailed you regarding this on your @i3m.upv.es email id. Kindly check

Regards

swarnim-cn avatar Jun 23 '20 15:06 swarnim-cn

@srisco
I tried doing this in two manners:

using the -jd flag -> I invoked the lambda function in this manner scar invoke -f test.yaml -jd '{"Name":"John", "Age"=22}' . However, in my event object, this data is not in the form of json. The corresponding event object is this -> {'resource': '/{proxy+}', 'path': '/launch', 'httpMethod': 'POST', 'headers': {'Accept': '/', 'Accept-Encoding': 'gzip, deflate', 'Content-Type': 'application/json', 'Host': 'iasduhvi21.execute-api.us-east-1.amazonaws.com', 'User-Agent': 'python-requests/2.23.0', 'X-Amzn-Trace-Id': 'Root=1-5ef22967-3f07d90438506b1459e474f3', 'X-Forwarded-For': '223.225.226.3', 'X-Forwarded-Port': '443', 'X-Forwarded-Proto': 'https'}, 'multiValueHeaders': {'Accept': ['/'], 'Accept-Encoding': ['gzip, deflate'], 'Content-Type': ['application/json'], 'Host': ['iasduhvi21.execute-api.us-east-1.amazonaws.com'], 'User-Agent': ['python-requests/2.23.0'], 'X-Amzn-Trace-Id': ['Root=1-5ef22967-3f07d90438506b1459e474f3'], 'X-Forwarded-For': ['223.225.226.3'], 'X-Forwarded-Port': ['443'], 'X-Forwarded-Proto': ['https']}, 'queryStringParameters': None, 'multiValueQueryStringParameters': None, 'pathParameters': {'proxy': 'launch'}, 'stageVariables': None, 'requestContext': {'resourceId': '81opwu', 'resourcePath': '/{proxy+}', 'httpMethod': 'POST', 'extendedRequestId': 'OltoQHTTIAMFccQ=', 'requestTime': '23/Jun/2020:16:10:15 +0000', 'path': '/scar/launch', 'accountId': '069379984339', 'protocol': 'HTTP/1.1', 'stage': 'scar', 'domainPrefix': 'iasduhvi21', 'requestTimeEpoch': 1592928615966, 'requestId': '25828803-6a7e-41f5-99bd-cc119eb229c9', 'identity': {'cognitoIdentityPoolId': None, 'accountId': None, 'cognitoIdentityId': None, 'caller': None, 'sourceIp': '223.225.226.3', 'principalOrgId': None, 'accessKey': None, 'cognitoAuthenticationType': None, 'cognitoAuthenticationProvider': None, 'userArn': None, 'userAgent': 'python-requests/2.23.0', 'user': None}, 'domainName': 'iasduhvi21.execute-api.us-east-1.amazonaws.com', 'apiId': 'iasduhvi21'}, 'body': 'Name=John&Age=22', 'isBase64Encoded': False}

In this, the 'body' is not in json format hence it's giving me an error while executing the lambda function. 'body': 'Name=John&Age=22' is not json format.

Using the -p flag -> I invoked the lambda function in this manner scar invoke -f test.yaml -jd '{"Name":"John", "Age"=22}'. This was in the correct json format. But when I checked the file corresponding to INPUT_FILE_PATH there is nothing there so I was not able to extract these parameters.

swarnim-cn avatar Jun 23 '20 23:06 swarnim-cn