-
Notifications
You must be signed in to change notification settings - Fork 0
/
samtemplate.yaml
75 lines (70 loc) · 3.11 KB
/
samtemplate.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
# Lambda function for your visitor counter logic
VisitorCounterFunction:
Type: AWS::Serverless::Function
Properties:
Handler: lambda_function.lambda_handler # Adjust if your filename/handler is different
Runtime: python3.8
CodeUri: s3://pwoodresumebackend/lambda_function.zip
Environment:
Variables:
TABLE_NAME: !Ref VisitorCounterTable # Passes the table name as an environment variable
Policies:
- DynamoDBReadPolicy:
TableName: !Ref VisitorCounterTable
- DynamoDBWritePolicy:
TableName: !Ref VisitorCounterTable
Role: arn:aws:iam::853234049808:role/service-role/ExpenseTracker-role-q4ydxqcj
# DynamoDB table to store the visitor count
VisitorCounterTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: VisitorCounterTable
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: CounterID
AttributeType: N # Number type for the counter
- AttributeName: DateRecorded
AttributeType: S # String type for recording dates
KeySchema:
- AttributeName: CounterID
KeyType: HASH # Hash key for fast lookups
- AttributeName: DateRecorded
KeyType: RANGE # Range key to query within date ranges
# API Creation
VisitorCounterApi:
Type: AWS::Serverless::HttpApi # Switch to AWS::Serverless::HttpApi
Properties:
StageName: prod
DefinitionBody:
openapi: 3.0.1 # Use appropriate OpenAPI version for HTTP APIs
info:
title: "Visitor Counter API"
paths:
/visitor-count:
get:
x-amazon-apigateway-integration:
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VisitorCounterFunction.Arn}/invocations
passthroughBehavior: when_no_match
httpMethod: GET
type: aws_proxy
post:
x-amazon-apigateway-integration:
uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VisitorCounterFunction.Arn}/invocations
passthroughBehavior: when_no_match
httpMethod: POST
type: aws_proxy
VisitorCounterApiIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref VisitorCounterApi
IntegrationType: AWS_PROXY
IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VisitorCounterFunction.Arn}/invocations
PayloadFormatVersion: '2.0' # Adjust if needed for your Lambda's expected behavior
Outputs:
VisitorCounterApiUrl:
Value: !Sub "https://${VisitorCounterApi}.execute-api.${AWS::Region}.amazonaws.com/prod/visitor-count"
VisitorCounterFunctionArn:
Value: !Sub "${VisitorCounterFunction.Arn}"