Skip to content

Instantly share code, notes, and snippets.

@ejdoh1
Created August 7, 2019 02:21
Show Gist options
  • Save ejdoh1/d90d5cae3a488d0147a24c20e8351a83 to your computer and use it in GitHub Desktop.
Save ejdoh1/d90d5cae3a488d0147a24c20e8351a83 to your computer and use it in GitHub Desktop.
Serverless Call IAM Authenticated AWS API Gateway
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)
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