I have a container that runs fine locally consisting of a simple python script that accepts a dictionary converted to a string as a system argument and prints out the key/value pairs:
calc.py:
import sys
import json
if __name__ == "__main__":
print("Entered in main")
print(f"Function name: {sys.argv[0]}")
#load
print(sys.argv[1])
payload = json.loads(sys.argv[1])
for k,v in payload.items():
print(f"Key: {k},Value: {v}")
I build this as a docker container using an entrypoint with an environmental varible:
ENTRYPOINT python3 calc.py "${LAMBDA_PAYLOAD}"
This allows me to run a test docker script of
docker run -e LAMBDA_PAYLOAD="{\"names\":\"J.J. Robichard\",\"Age\":25}" calc
which successfully prints out the key/value pairs.
When I put this into an AWS ECS Fargate task using boto3 and overriding the environmental variable by using:
'environment': [
{
'name': 'LAMBDA_PAYLOAD',
'value': "{\"names\":[\"J.J. Robichard\",\"April\"],\"years\":[25,29]}"
},
],
I get the print(sys.argv[1]) returns:
{"names":["J.J.
and everything breaks down. How do I get the task to accept a string with space? I've tried "\ " and f"""{}""", but nothing is working.