Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
swarnim-cn opened this issue Jun 23, 2020 · 3 comments

Comments

@swarnim-cn
Copy link

swarnim-cn commented Jun 23, 2020

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?

@srisco
Copy link
Contributor

srisco commented Jun 23, 2020

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.

@swarnim-cn
Copy link
Author

swarnim-cn commented Jun 23, 2020

Hi @srisco

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

Regards

@swarnim-cn
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants