This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding native support of ALB requests * Adding the raw event to the minik event
- Loading branch information
1 parent
7c3b5b5
commit 2ea04f7
Showing
33 changed files
with
952 additions
and
213 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,4 +106,7 @@ venv.bak/ | |
|
||
# Python3 virtual env | ||
venv3/ | ||
tvenv/ | ||
tvenv/ | ||
|
||
# VS Code | ||
.vscode |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
s3_bucket=temp-${profile} | ||
stack_name ?= minik-alb | ||
sam_template_base=sam | ||
sam_template=$(sam_template_base).yml | ||
sam_output=$(sam_template_base)-new.yml | ||
|
||
|
||
build: | ||
juni build | ||
|
||
deploy: | ||
sam package \ | ||
--s3-bucket $(s3_bucket) \ | ||
--template-file $(sam_template) \ | ||
--output-template-file ./dist/$(sam_output) \ | ||
--profile $(profile) | ||
|
||
sam deploy \ | ||
--template-file ./dist/$(sam_output) \ | ||
--stack-name $(stack_name) \ | ||
--capabilities CAPABILITY_IAM \ | ||
--region us-east-1 \ | ||
--profile $(profile) |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from minik.core import Minik | ||
|
||
app = Minik() | ||
|
||
req_type_by_name = { | ||
'api_request': 'API Gateway!', | ||
'alb_request': 'ALB!' | ||
} | ||
|
||
|
||
@app.get("/events") | ||
def get_events(): | ||
""" | ||
The view handler for the `/events` route, this function will return an html | ||
response with a list of events. Each event points to another route to get | ||
more information on the event. | ||
This view will also display the request type based on the service that invoked | ||
the lambda function. Minik supports request from API Gateway and Application | ||
Load Balancer natively. | ||
""" | ||
|
||
app.response.headers = { | ||
"Content-Type": "text/html; charset=utf-8", | ||
"Access-Control-Allow-Origin": "*", | ||
"Access-Control-Allow-Methods": "GET", | ||
"Access-Control-Allow-Headers": "Content-Type,X-Amz-Date", | ||
"Authorization": "X-Api-Key,X-Amz-Security-Token" | ||
} | ||
|
||
req_type = req_type_by_name.get(app.request.request_type) | ||
|
||
return f""" | ||
<html> | ||
<head> | ||
<title>Hello from {req_type}</title> | ||
</head> | ||
<body> | ||
<h1>Hello from {req_type}</h1> | ||
<a href="/events/20902">Silver Spring Events</a> | ||
<a href="/events/32608">Alachua County Events</a> | ||
</body> | ||
</html>""" | ||
|
||
|
||
@app.get("/events/{zip_code}") | ||
def get_event(zip_code: int): | ||
"""Very simple handler that returns a json response based on the zip code.""" | ||
|
||
if zip_code == 20902: | ||
return {'events': ['MD Gran fondo', 'Old Busthead']} | ||
|
||
return {'events': ['other events']} | ||
|
||
|
||
@app.post("/events/{zip_code}") | ||
def post_event(zip_code: int): | ||
""" An echo function to return the body and zip of the request.""" | ||
# Store a new event | ||
return {'zip_code': zip_code, 'post_data': app.request.json_body} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
functions: | ||
events: | ||
requirements: ./requirements.txt | ||
include: | ||
- ./lambda_function/lambda_handler.py | ||
- ../../minik |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Description: API Gateway with Lambda Token Authorizer | ||
Resources: | ||
|
||
EventsFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
# This function uses the python 3.6 runtime. | ||
Runtime: python3.6 | ||
|
||
# This is the Lambda function's handler. | ||
Handler: lambda_handler.app | ||
|
||
# The location of the Lambda function code. | ||
CodeUri: ./dist/events.zip |
Oops, something went wrong.