-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
125 lines (125 loc) · 3.69 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
Transform: AWS::Serverless-2016-10-31
Resources:
AddRepo:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-AddRepo
Description: !Sub
- Stack ${AWS::StackName} Function ${ResourceName}
- ResourceName: AddRepo
CodeUri: src/AddRepo
Handler: index.handler
Runtime: nodejs20.x
MemorySize: 1024
Timeout: 30
Tracing: Active
Environment:
Variables:
REPOS_TABLE_NAME: !Ref Repos
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref Repos
Events:
CodeCupidApiPOSTrepo:
Type: Api
Properties:
Path: /repo
Method: POST
RestApiId: !Ref CodeCupidApi
ListReposByLanguage:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${AWS::StackName}-ListReposByLanguage
Description: !Sub
- Stack ${AWS::StackName} Function ${ResourceName}
- ResourceName: ListReposByLanguage
CodeUri: src/ListReposByLanguage
Handler: index.handler
Runtime: nodejs20.x
MemorySize: 1024
Timeout: 30
Tracing: Active
Environment:
Variables:
REPOS_TABLE_NAME: !Ref Repos
Policies:
- DynamoDBReadPolicy:
TableName: !Ref Repos
Events:
CodeCupidApiGETreposlanguage:
Type: Api
Properties:
Path: /repos/{language}
Method: GET
RestApiId: !Ref CodeCupidApi
CodeCupidApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub
- ${ResourceName} From Stack ${AWS::StackName}
- ResourceName: CodeCupidApi
StageName: prod
DefinitionBody:
openapi: '3.0'
info: {}
paths:
/repos/{language}:
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ListReposByLanguage.Arn}/invocations
responses: {}
/repo:
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AddRepo.Arn}/invocations
responses: {}
EndpointConfiguration: REGIONAL
TracingEnabled: true
Cors:
MaxAge: 5
AllowMethods: '''GET,POST'''
AllowHeaders: '''Content-Type,X-Amz-Date,Authorization,X-Api-Key'''
AllowOrigin: '''*'''
Frontend:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub ${AWS::StackName}-frontend-${AWS::AccountId}
WebsiteConfiguration:
IndexDocument: index.html
Repos:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: language
AttributeType: S
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: id
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: languageIndex
KeySchema:
- AttributeName: language
KeyType: HASH
Projection:
ProjectionType: ALL
Outputs:
ApiURL:
Description: The URL for the API
Value: !Sub https://${CodeCupidApi}.execute-api.${AWS::Region}.amazonaws.com/prod/
FrontendURL:
Description: The URL of the S3 bucket containing the built frontend
Value: !GetAtt Frontend.WebsiteURL
Metadata:
AWS::Composer::Groups:
Group:
Label: API Compute
Members:
- ListReposByLanguage
- AddRepo