Created
February 14, 2019 04:41
-
-
Save ejdoh1/e74ed6df7d94de5f7a6b2a567b6306b6 to your computer and use it in GitHub Desktop.
AWS Lambda function to call API Gateway with IAM auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: Allow Lambda action "execute-api:*" on your AWS API Gateway resources | |
import os | |
import requests | |
from requests_aws4auth import AWS4Auth | |
REGION = 'ap-southeast-2' | |
METHOD = 'POST' | |
SERVICE = 'execute-api' | |
DATA = {'key':'value'} | |
URL = "https://xyz.execute-api.ap-southeast-2.amazonaws.com/stage/method" | |
def handler(event,context): | |
aws_auth = AWS4Auth( | |
os.environ['AWS_ACCESS_KEY_ID'], | |
os.environ['AWS_SECRET_ACCESS_KEY'], | |
REGION, | |
SERVICE, | |
session_token=os.environ['AWS_SESSION_TOKEN'] | |
) | |
r = requests.request(METHOD, URL,data=DATA,auth=aws_auth) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment