Created
August 7, 2019 02:21
-
-
Save ejdoh1/d90d5cae3a488d0147a24c20e8351a83 to your computer and use it in GitHub Desktop.
Serverless Call IAM Authenticated AWS API Gateway
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
from botocore.vendored import requests | |
from requests_aws4auth import AWS4Auth | |
import os | |
URL = "https://myurl.com" | |
REGION = 'ap-southeast-2' | |
METHOD = 'GET' | |
SERVICE = 'execute-api' | |
def handler(event, context): | |
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, auth=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
service: sample-service | |
provider: | |
name: aws | |
runtime: python2.7 | |
region: ap-southeast-2 | |
iamRoleStatements: | |
- Effect: Allow | |
Action: "execute-api:*" | |
Resource: "*" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment