-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudformation-resources-v1.yaml
93 lines (86 loc) · 2.79 KB
/
cloudformation-resources-v1.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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: Compute resources.
Parameters:
LambdaFunctionImageUri:
Type: String
Resources:
# --- CloudWatch ---
LogsLogGroupHttpApiAccessLog:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub ${AWS::StackName}HttpApiAccessLog
RetentionInDays: 30
# --- HTTP APIs ---
ApiGatewayApiHttp:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: !Sub ${AWS::StackName}ApiGatewayApiHttp
ProtocolType: HTTP
CorsConfiguration:
AllowOrigins:
- "*"
AllowMethods:
- "*"
AllowHeaders:
- "*"
ExposeHeaders:
- "*"
# --- HTTP APIs stage ---
ApiGatewayStageHttpDefault:
Type: AWS::ApiGatewayV2::Stage
Properties:
ApiId: !Ref ApiGatewayApiHttp
StageName: $default
AutoDeploy: true
DefaultRouteSettings:
DetailedMetricsEnabled: true
AccessLogSettings:
DestinationArn: !GetAtt LogsLogGroupHttpApiAccessLog.Arn
Format: >
{"requestId": "$context.requestId", "ip": "$context.identity.sourceIp", "caller": "$context.identity.caller", "user": "$context.identity.user", "requestTime": "$context.requestTime", "routeKey": "$context.routeKey", "status": "$context.status"}
# --- HTTP APIs route: POST /graphql ---
ApiGatewayRoutePostGraphql:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref ApiGatewayApiHttp
RouteKey: "POST /graphql"
Target: !Join ["/", [integrations, !Ref ApiGatewayIntegrationPostGraphql]]
ApiGatewayIntegrationPostGraphql:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref ApiGatewayApiHttp
IntegrationMethod: POST
IntegrationType: AWS_PROXY
IntegrationUri: !GetAtt LambdaFunction.Arn
PayloadFormatVersion: "2.0"
# --- HTTP APIs route: GET /graphql ---
ApiGatewayRouteGetGraphql:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref ApiGatewayApiHttp
RouteKey: "GET /graphql"
Target: !Join ["/", [integrations, !Ref ApiGatewayIntegrationGetGraphql]]
ApiGatewayIntegrationGetGraphql:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref ApiGatewayApiHttp
IntegrationMethod: GET
IntegrationType: AWS_PROXY
IntegrationUri: !GetAtt LambdaFunction.Arn
PayloadFormatVersion: "2.0"
# --- Serverless Application Model (SAM) ---
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Architectures:
- arm64
PackageType: Image
ImageUri: !Ref LambdaFunctionImageUri
Tracing: Active
LambdaPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref LambdaFunction
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com