forked from aws-samples/serverless-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yml
113 lines (103 loc) · 3.25 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
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: An Application Load Balancer and an AWS Lambda function. (uksb-1tthgi812) (tag:alb-lambda-rust)
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
Subnets:
Type: List<AWS::EC2::Subnet::Id>
# Global values that are applied to all applicable resources in this template
Globals:
Function:
MemorySize: 128
Architectures: ["arm64"]
Handler: bootstrap
Runtime: provided.al2
Timeout: 29
Environment:
Variables:
RUST_BACKTRACE: 1
RUST_LOG: info
Resources:
##########################################################################
# Lambda Function #
##########################################################################
MyLambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: ./build/handler
Policies:
- AWSLambdaBasicExecutionRole
Tags:
name: !Ref AWS::StackName
MyLambdaFunctionPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt MyLambdaFunction.Arn
Action: lambda:InvokeFunction
Principal: elasticloadbalancing.amazonaws.com
##########################################################################
# Application Load Balancer #
##########################################################################
MyLoadBalancer:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Type: application
Scheme: internet-facing
IpAddressType: dualstack
Subnets: !Ref Subnets
SecurityGroups: [!Ref MySecurityGroup]
Tags:
- Key: name
Value: !Ref AWS::StackName
MyTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
DependsOn: MyLambdaFunctionPermission
Properties:
TargetType: lambda
Targets:
- Id: !GetAtt MyLambdaFunction.Arn
Tags:
- Key: name
Value: !Ref AWS::StackName
MyHttpListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
LoadBalancerArn: !Ref MyLoadBalancer
Port: 80
Protocol: HTTP
DefaultActions:
- TargetGroupArn: !Ref MyTargetGroup
Type: forward
# MyHttpsListener: #A certificate must be specified for HTTPS listeners
# Type: AWS::ElasticLoadBalancingV2::Listener
# Properties:
# LoadBalancerArn: !Ref MyLoadBalancer
# Port: 443
# Protocol: HTTPS
# Certificates:
# - !GetAtt MyListenerCertificate.Arn
# DefaultActions:
# - TargetGroupArn: !Ref MyTargetGroup
# Type: forward
MySecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupName: !Ref AWS::StackName
GroupDescription: Allow http on port 80 and 443
VpcId: !Ref VpcId
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
# - IpProtocol: tcp #A certificate must be specified for HTTPS listeners
# FromPort: 443
# ToPort: 443
# CidrIp: 0.0.0.0/0
Tags:
- Key: name
Value: !Ref AWS::StackName
Outputs:
DNSName:
Value: !GetAtt MyLoadBalancer.DNSName