I need to run HTTPie Command from withing the AWS Lambda
- I created a layer for HTTPie
- Added layer to my python function
- Running my HTTPie command from AWS Lambda which looks like below
import subprocess
def lambda_handler(req, context):
result = subprocess.call("/opt/python/bin/http GET https://reqres.in/api/users?page=2", shell=True)
return result
Function Logs:
/bin/sh: /opt/python/bin/http: Permission denied
Requirement:
The reason I am using HTTPie rather than requests is that I need to use different authentication mechanisms with my request. With requests I cannot make http calls with other authentication mechanisms which is important business requirement. Following are some of the examples we would be using and HTTPie provides all of those plugins
Signature, ApiAuth, AWS Auth, HMAC, JWTAuth, OAuth, OAuth2 and others
Solutions tried so far
- Created a package instead of layer, assign that package all permissions, zip it, assign all permissions to zip as well"chmos -R 777 folder" and uploaded to lambda as zip. This still gave me same issue.
- Added this to my code before using http
- result = subprocess.call("chmod -R 777 /opt/python/bin/http", shell=True)
- chmod: changing permissions of ‘/var/task/lokesh/bin/http’: Read-only file system
- /bin/sh: /var/task/lokesh/bin/http: Permission denied