-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemplate.yaml
84 lines (84 loc) · 2.63 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
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Lambda GraphQL function + DynamoDB.
Parameters:
EnvName:
Type: String
Description: Choose 'test' or 'prod'. This generates an alias, stage and sets NODE_ENV.
AllowedValues:
- test
- prod
Default: test
Mappings:
TablePrefixMap:
test:
Prefix: 'test_'
prod:
Prefix: ''
Resources:
GraphQLLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Description: An AWS Lambda GraphQL function.
FunctionName: !Sub graphql-lambda-function-${EnvName}
AutoPublishAlias: !Ref EnvName
Handler: src/lambda.handler
CodeUri: .
Runtime: nodejs10.x
MemorySize: 128
Timeout: 10
Tracing: Active
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MoviesTable
Events:
AnyRequest:
Type: Api
Properties:
Path: /graphql
Method: ANY
RestApiId: !Ref GraphQLApiGateway
Environment:
Variables:
NODE_ENV: !Ref EnvName
GraphQLApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: !Ref EnvName
TracingEnabled: True
MoviesTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Join
- ''
- - !FindInMap [TablePrefixMap, !Ref EnvName, Prefix]
- 'movies'
BillingMode: PAY_PER_REQUEST
KeySchema:
- AttributeName: year
KeyType: HASH
- AttributeName: title
KeyType: RANGE
AttributeDefinitions:
- AttributeName: year
AttributeType: N
- AttributeName: title
AttributeType: S
Outputs:
LambdaFunctionName:
Value: !Ref GraphQLLambdaFunction
LambdaFunctionARN:
Description: Lambda function ARN.
Value:
'Fn::GetAtt':
- GraphQLLambdaFunction
- Arn
ApiURL:
Description: 'API endpoint URL for the environment'
Value: !Sub https://${GraphQLApiGateway}.execute-api.${AWS::Region}.amazonaws.com/${EnvName}/graphql
MoviesTableARN:
Description: DynamoDB Movies table ARN.
Value:
'Fn::GetAtt':
- MoviesTable
- Arn