Skip to content

Commit

Permalink
Update public app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bb245 committed Jan 28, 2024
1 parent 7f5b393 commit c67874f
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions apigw-rest-api-iam-authorizer-sigv4a-sls-py/public/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@
from botocore.awsrequest import AWSRequest
from requests import request

secured_service_url = os.getenv('aws_iam_secured_service_url')


class AWSSigV4Requester:
def __init__(self, service='execute-api', region=os.getenv('AWS_REGION')):
self.service = service
self.region = region
apigw_component_service = 'execute-api'

def __init__(self):
self.service = self.apigw_component_service
self.region = os.getenv('AWS_REGION')
self.credentials = Session().get_credentials().get_frozen_credentials()

def sigv4_request(self, url, method='GET', body=None, params=None, headers=None):
def sigv4_request(self, url, method, body, params, headers):
req = AWSRequest(method=method, url=url, data=body, params=params, headers=headers)
SigV4Auth(self.credentials, self.service, self.region).add_auth(req)
req = req.prepare()
return request(method=req.method, url=req.url, headers=req.headers, data=req.body)

def call_aws_iam_secured_api(self, url):
response = self.sigv4_request(url=url, method='GET', headers={'content-type': 'application/json'})
def call_aws_iam_secured_api(self, url, method, body, params, headers):
response = self.sigv4_request(url=url, method=method, body=body, params=params,
headers=headers)
return response.json()


def handler(event, context):
aws_requester = AWSSigV4Requester()
result = aws_requester.call_aws_iam_secured_api(secured_service_url)
result = aws_requester.call_aws_iam_secured_api(url=os.getenv('aws_iam_secured_service_url'), method='GET',
body=None, params=None,
headers={'content-type': 'application/json'})
response = {
"statusCode": int(HTTPStatus.OK),
"body": json.dumps(result)
Expand Down

0 comments on commit c67874f

Please sign in to comment.