-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
98 lines (91 loc) · 3.1 KB
/
template.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
sam-python312-template
Parameters:
Stage:
Type: String
Default: local
AllowedValues:
- local
- dev
- stg
- prod
Description: Environment stage name
ApiVersion:
Type: String
Default: latest
Description: API Semantic Version
ApiCorsAllowedOrigins:
Type: String
Default: http://localhost:3000,http://localhost:3005
Description: comma separated allowed origins for CORS
Globals: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html
Function:
Timeout: 30
MemorySize: 1024
Runtime: python3.12
Tracing: Active
# You can add LoggingConfig parameters such as the Log format, Log Group, and SystemLogLevel or ApplicationLogLevel. Learn more here https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-loggingconfig.
LoggingConfig:
LogFormat: JSON
Environment:
Variables:
STAGE: !Ref Stage
Api:
TracingEnabled: true
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref Stage
Name: !Sub "${Stage}-sam-api"
Description: "API Gateway for SAM Python 3.12"
Cors:
AllowMethods: "'GET,POST,OPTIONS,PUT,DELETE,PATCH'"
AllowHeaders: "'Content-Type,Authorization'"
Tags:
STAGE: !Ref Stage
ApiHandler:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
FunctionName: !Sub "${Stage}-sam-APIHandler"
Handler: v1/handlers/app.lambda_handler
CodeUri: src
Description: Api handler function
Architectures:
- x86_64
Tracing: Active
Events:
RestApi:
Type: Api # More info about API Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-api.html
Properties:
RestApiId: !Ref ApiGateway
Path: /{proxy+}
Method: ANY
Environment:
Variables:
API_VERSION: !Ref ApiVersion
API_CORS_ALLOWED_ORIGINS: !Ref ApiCorsAllowedOrigins
POWERTOOLS_SERVICE_NAME: SamApiService
POWERTOOLS_METRICS_NAMESPACE: SamApi
LOG_LEVEL: INFO
Tags:
LambdaPowertools: python
ApplicationResourceGroup:
Type: AWS::ResourceGroups::Group
Properties:
Name: !Sub ApplicationInsights-SAM-${AWS::StackName}
ResourceQuery:
Type: CLOUDFORMATION_STACK_1_0
ApplicationInsightsMonitoring:
Type: AWS::ApplicationInsights::Application
Properties:
ResourceGroupName: !Ref ApplicationResourceGroup
AutoConfigurationEnabled: true
Outputs:
ApiGatewayUrl:
Description: "API Swagger URL"
Value: !Sub "https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${Stage}/swagger"
Export:
Name: !Sub "${AWS::StackName}-ApiUrl"