This repository was archived by the owner on Jun 29, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.yml
More file actions
135 lines (122 loc) · 4.33 KB
/
template.yml
File metadata and controls
135 lines (122 loc) · 4.33 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: '2010-09-09'
Description: Application to forward SES email to another address
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Tracing: Active
MemorySize: 128
Timeout: 30
Runtime: nodejs16.x
Architectures:
- x86_64
Api:
TracingEnabled: True
Parameters:
ProxyDomain:
Description: Domain for proxying. Receiving all Emails and sending them to "ForwardToAddress"
Type: String
ForwardToAddress:
Description: Email forwarded to address
Type: String
SESRuleSetARN:
Description: ARN of a SES Rule Set. The template will create a new one if not provided
Type: String
Default: ''
Conditions:
CreateReceiptRuleSet: !Equals [!Ref SESRuleSetARN, '']
Resources:
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
# This is a Lambda function config associated with the source code: process-incoming-email.js
ProcessIncomingEmailFunction:
Type: AWS::Serverless::Function
Properties:
Description: A Lambda function that forwards email from a SNS Topic to a given Email-Address.
CodeUri: process-incoming-email/
Handler: app.handler
Layers:
- !Ref ProcessIncomingEmailLayer
Environment:
Variables:
PROXY_DOMAIN: !Ref ProxyDomain
FORWARD_TO: !Ref ForwardToAddress
Policies:
# Give Lambda basic execution Permission
- AWSLambdaBasicExecutionRole
- Statement:
- Sid: SESEmailForward
Effect: Allow
Action:
- ses:SendEmail
- ses:SendRawEmail
Resource: '*'
Metadata: # Manage esbuild properties
BuildMethod: esbuild
BuildProperties:
Minify: true
Target: 'es2020'
Sourcemap: false
External:
- aws-sdk
- envalid
EntryPoints:
- app.ts
ProcessIncomingEmailLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: aws-email-forwarder-dependencies
Description: Dependencies for AWS Email Forwarder
ContentUri: dependencies/
CompatibleArchitectures:
- x86_64
CompatibleRuntimes:
- nodejs16.x
LicenseInfo: 'MIT'
RetentionPolicy: Retain
SNSEmailReceiveTopic:
Type: AWS::SNS::Topic
Properties:
Subscription:
- Endpoint: !GetAtt ProcessIncomingEmailFunction.Arn
Protocol: lambda
SNSLambdaInvokeRole:
Type: AWS::Lambda::Permission
Properties:
Action: lambda:InvokeFunction
Principal: sns.amazonaws.com
SourceArn: !Ref SNSEmailReceiveTopic
FunctionName: !GetAtt ProcessIncomingEmailFunction.Arn
SESReceiptRuleSet:
Type: AWS::SES::ReceiptRuleSet
Condition: CreateReceiptRuleSet
Properties:
RuleSetName: receiving-rule-set
SESReceiptRule:
Type: AWS::SES::ReceiptRule
Properties:
Rule:
Actions:
- SNSAction:
TopicArn: !Ref SNSEmailReceiveTopic
Encoding: UTF-8
Enabled: true
Name: forward-incoming-mail
Recipients:
- !Ref ProxyDomain
ScanEnabled: true
TlsPolicy: Optional
RuleSetName: !If [CreateReceiptRuleSet, !Ref SESReceiptRuleSet, !Ref SESRuleSetARN]
Outputs:
ProcessIncomingEmailFunction:
Description: 'Process Incoming Email Lambda Function ARN'
Value: !GetAtt ProcessIncomingEmailFunction.Arn