This repository has been archived by the owner on Jul 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yml
113 lines (103 loc) · 2.74 KB
/
template.yml
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
# Serverless Application Model (SAM) definitions
AWSTemplateFormatVersion: '2010-09-09'
Transform:
- 'AWS::Serverless-2016-10-31'
Description:
Creates a RESTful API using API Gateway and Lambda
Globals:
Function:
Runtime: nodejs8.10
Timeout: 60
Tags:
stage:
Ref: StageName
Parameters:
# CodeDeployRole:
# Type: String
# Description: IAM role to allow AWS CodeDeploy to manage deployment of AWS Lambda functions
RepositoryName:
Type: String
Description: Name of the git repo being deployed
StageName:
Type: String
Default: dev
Description: The Lambda Function Stage
S3BucketName:
Type: String
Description: The name of the S3 bucket in which the Swagger specification can be found.
Resources:
RestApi:
Type: AWS::Serverless::Api
Properties:
Name:
Fn::Sub: ${RepositoryName}-${StageName}
StageName:
Ref: StageName
DefinitionBody:
Fn::Transform:
Name: AWS::Include
Parameters:
Location:
Fn::Join:
- ''
- - 's3://'
- Ref: S3BucketName
- '/swagger.yml'
SearchInventoryDemo:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'searchInventoryDemo'
Runtime: nodejs8.10
CodeUri: inventory
Handler: index.searchInventory
Description: Search Inventory
Timeout: 10
Events:
GET:
Type: Api
Properties:
RestApiId:
Ref: RestApi
Path: /inventory
Method: get
Role: !GetAtt LambdaExecutionRole.Arn
AddInventoryDemo:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'addInventoryDemo'
Runtime: nodejs8.10
CodeUri: inventory
Handler: index.addInventory
Description: Adds inventory
Timeout: 10
Events:
POST:
Type: Api
Properties:
RestApiId:
Ref: RestApi
Path: /inventory
Method: post
Role: !GetAtt LambdaExecutionRole.Arn
LambdaExecutionRole:
Description: Creating service role in IAM for AWS Lambda
Type: AWS::IAM::Role
Properties:
RoleName: !Sub '${RepositoryName}-Execution-${StageName}'
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [lambda.amazonaws.com]
Action: sts:AssumeRole
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Outputs:
ApiUrl:
Value:
Fn::Join:
- ""
- - "https://"
- Ref: RestApi
- Fn::Sub: ".execute-api.${AWS::Region}.amazonaws.com/dev"