Skip to content

Commit

Permalink
Implement OPTIONS method to make CORS Preflight work
Browse files Browse the repository at this point in the history
  • Loading branch information
tillkahlbrock committed Sep 25, 2019
1 parent 2094417 commit dd55804
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions workshop-files/create_url/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
dynamodb = boto3.client('dynamodb')

def lambda_handler(event, context):
if event["httpMethod"] == "OPTIONS":
return {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Credentials" : True,
"Access-Control-Allow-Headers": "authorization, content-type"
}
}

table_name = os.environ['TABLE_NAME']
post_parameters = json.loads(event["body"])
url_to_shorten = post_parameters['url']
Expand Down
8 changes: 8 additions & 0 deletions workshop-files/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Resources:
RestApiId: !Ref ShortenerApi
Path: /short
Method: post
ProxyApiCors:
Type: Api
Properties:
RestApiId: !Ref ShortenerApi
Path: /short
Method: OPTIONS
Auth:
Authorizer: NONE
Environment:
Variables:
TABLE_NAME: !Ref DynamoDBTable
Expand Down

0 comments on commit dd55804

Please sign in to comment.