-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yaml
More file actions
107 lines (100 loc) · 4.64 KB
/
template.yaml
File metadata and controls
107 lines (100 loc) · 4.64 KB
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
---
# Look at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html
# and https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md
# for information on how to use this template
AWSTemplateFormatVersion: 2010-09-09 # Defines this YAMl as a cloudformation template
Transform: AWS::Serverless-2016-10-31 # Integrates SAM into the template
Description: Boilerplate SAM template.
Parameters: # Parameters that you can set outside of your template to pass values to it
DomainName:
Type: String
Description: Domain name for things
Default: domain.com
Certificate: # The ARN of your certificate, should look something like:
Type: String # arn:aws:acm:eu-west-1:867530202211:certificate/658a382b-563e-40bb-8098-e073385310bf
Description: Certificate for custom domain
Default: arn:aws:acm:region:numbers:certificate/uuid
Subdomain:
Type: String
Description: Subdomain of your site
Default: api.
Globals:
Api:
Cors: # Use if you want CORS otherwise remove this
AllowMethods: "'*'" # CORS has caused me headaches in the past so it might be worth
AllowHeaders: "'*'" # it to remove this entirely
AllowOrigin: !Sub "'https://${DomainName}'"
Resources:
route53Domain: # Creates a domain in Route53 with api as the prefix e.g. api.domain.com
Type: AWS::Route53::RecordSetGroup # This guide assumes you have a Route53 domain to use
Properties:
HostedZoneName: !Sub ${DomainName}.
RecordSets:
- Name: !Join
- ''
- - !Ref Subdomain # Change this if you want a different sub-domain
- !Ref DomainName
- '.'
Type: A
AliasTarget:
HostedZoneId: !GetAtt ApiDomainName.DistributionHostedZoneId
DNSName: !GetAtt ApiDomainName.DistributionDomainName
BasePathMapping: # Creates a API Gateway stage called prod
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: !Sub ${Subdomain}${DomainName}
RestApiId:
Ref: RestApi
Stage: prod
DependsOn: RestApiprodStage
ApiDomainName: # Assigns the domain's certificate to API Gateway
Type: AWS::ApiGateway::DomainName
Properties:
DomainName: !Sub ${Subdomain}${DomainName}
CertificateArn: !Ref Certificate
RestApi: # Creates an API with stage Prod
Type: AWS::Serverless::Api
Properties:
Name: RestApi
StageName: prod
lambdaFunction: # Creates a lambda function
Type: AWS::Serverless::Function
Properties:
CodeUri: src/index.js # Specify where in your directory the code is
Handler: index.handler # Specify the name of lambda's entry function
Role: !GetAtt lambdaRole.Arn # A role defined in the template
Runtime: nodejs8.10 # Change runtime to whatever language you are suing e.g. python3.6
Events:
lambdaAPI:
Type: Api # Assigns the lambda function an API call
Properties:
Path: /lambdafunction # Put your path here! e.g. api.domain.com/lambdafunction
Method: get # Put your method here! e.g. post, get, put, delete...
RestApiId: !Ref RestApi
lambdaRole:
Type: AWS::IAM::Role
Properties:
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Policies: # Put your policy documents here. What follows is an
- PolicyName: s3GetPutPolicy # example of a policy that allows GetObject access to all objects
PolicyDocument: # in a particular bucket, defined later in this template
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource:
- !GetAtt fileServerBucket.Arn
- !Sub ${fileServerBucket.Arn}/*
fileServerBucket: # Sample bucket, only necessary if you want a bucket
Type: AWS::S3::Bucket