Skip to content

Commit b8cc8b5

Browse files
Jade WibbelsJade Wibbels
authored andcommitted
added lambda handler and some Make commands
1 parent 331a2a8 commit b8cc8b5

File tree

4 files changed

+85
-2
lines changed

4 files changed

+85
-2
lines changed

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,47 @@ venv:
4040
.PHONY: clean
4141
clean:
4242
rm -rf $(VENV)
43+
44+
# Create DynamoDB table
45+
.PHONY: create-dynamodb-table
46+
create-dynamodb-table:
47+
@echo "Creating DynamoDB table with name: $(TABLE_NAME)"
48+
aws dynamodb create-table \
49+
--table-name $(TABLE_NAME) \
50+
--attribute-definitions $(ATTRIBUTE_DEFINITIONS) \
51+
--key-schema $(KEY_SCHEMA) \
52+
--provisioned-throughput $(PROVISIONED_THROUGHPUT)
53+
54+
# Usage: make create-dynamodb-table TABLE_NAME=my-table ATTRIBUTE_DEFINITIONS="AttributeName=Id,AttributeType=S" KEY_SCHEMA="AttributeName=Id,KeyType=HASH" PROVISIONED_THROUGHPUT="ReadCapacityUnits=5,WriteCapacityUnits=5"
55+
56+
# Create Lambda function
57+
.PHONY: create-lambda-function
58+
create-lambda-function:
59+
@echo "Creating Lambda function with name: $(FUNCTION_NAME)"
60+
aws lambda create-function \
61+
--function-name $(FUNCTION_NAME) \
62+
--runtime python3.9 \
63+
--role $(ROLE) \
64+
--handler src.lambda_function.lambda_handler \
65+
--zip-file fileb://$(ZIP_FILE)
66+
67+
# Usage: make create-lambda-function FUNCTION_NAME=my-function ROLE=arn:aws:iam::123456789012:role/execution_role ZIP_FILE=function.zip
68+
69+
# Create API Gateway
70+
.PHONY: create-api-gateway
71+
create-api-gateway:
72+
@echo "Creating API Gateway with name: $(API_NAME)"
73+
aws apigatewayv2 create-api \
74+
--name $(API_NAME) \
75+
--protocol-type $(PROTOCOL_TYPE) \
76+
--target $(TARGET) \
77+
78+
# Usage: make create-api-gateway API_NAME=my-api API_DESCRIPTION="My API Gateway"
79+
80+
# Create route in API Gateway
81+
.PHONY: create-route
82+
create-route:
83+
@echo "Creating route in API Gateway with name: $(ROUTE_NAME)"
84+
aws apigatewayv2 create-route \
85+
--api-id $(API_ID) \
86+
--route-key $(ROUTE_KEY) \

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ pytest
22
pytest-asyncio
33
pytest-cov
44

5-
requests == 2.32.*
5+
boto3 == 1.35.72
66
pydantic == 2.9.*
77
datamodel-code-generator == 0.26.*
8-
websockets == 10.0.*
8+
9+
910

1011
black
1112
flake8

src/awscli.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Put AWS CLI commands here

src/lambda_function.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import boto3
2+
import json
3+
import logging
4+
5+
logging.basicConfig(level=logging.INFO)
6+
7+
8+
dynamo = boto3.client("dynamodb", region_name="us-east-1")
9+
table_name = "my-table" # Replace with your table name
10+
11+
def lambda_handler(event, context):
12+
"""
13+
Lambda handler function
14+
15+
Args:
16+
event (dict): Event data
17+
context (object): Runtime information
18+
19+
"""
20+
logging.info(f"Received event: {json.dumps(event, indent=2)}")
21+
22+
http_method = event["requestContext"]["http"]["method"]
23+
path = event["requestContext"]["http"]["path"]
24+
25+
response = {}
26+
27+
# Call the appropriate function based on the HTTP method
28+
try:
29+
logging.info("Update with API values here")
30+
body = {"message": "Hello from Lambda!"}
31+
except Exception as e:
32+
logging.error(f"Error: {e}")
33+
response["statusCode"] = 500,
34+
body = json.dumps({"error": str(e)}),
35+
36+
response["headers"] = {"Content-Type": "application/json"}
37+
response["body"] = json.dumps(body)

0 commit comments

Comments
 (0)