AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: APPNAMEHERE Lambda (ALB) Parameters: RailsEnv: Type: String Default: production AllowedValues: - staging - production VpcId: Type: AWS::EC2::VPC::Id Subnets: Type: List Resources: RailsLoadBalancer: Type: AWS::ElasticLoadBalancingV2::LoadBalancer Properties: Name: APPNAMEHERE Scheme: internet-facing Subnets: !Ref Subnets SecurityGroups: - !Ref RailsSecurityGroup RailsLoadBalancerTargetGroup: Type: AWS::ElasticLoadBalancingV2::TargetGroup DependsOn: RailsFunctionInvokePermission Properties: TargetType: lambda TargetGroupAttributes: - Key: lambda.multi_value_headers.enabled Value: true Targets: - Id: !GetAtt RailsFunction.Arn RailsLoadBalancerHttpListener: Type: 'AWS::ElasticLoadBalancingV2::Listener' Properties: DefaultActions: - TargetGroupArn: !Ref RailsLoadBalancerTargetGroup Type: forward LoadBalancerArn: !Ref RailsLoadBalancer Port: 80 Protocol: HTTP RailsSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow HTTP VpcId: !Ref VpcId SecurityGroupIngress: - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 RailsFunctionInvokePermission: Type: AWS::Lambda::Permission Properties: FunctionName: !GetAtt RailsFunction.Arn Action: 'lambda:InvokeFunction' Principal: elasticloadbalancing.amazonaws.com RailsFunction: Type: AWS::Serverless::Function Properties: CodeUri: . Handler: app.handler Runtime: ruby2.5 MemorySize: 512 Timeout: 30 Environment: Variables: RAILS_ENV: !Ref RailsEnv FunctionName: !Join [ '', [ 'APPNAMEHERE-', !Ref RailsEnv, '-', !Ref 'AWS::Region' ] ] AutoPublishAlias: live Outputs: RailsLoadBalancerDNSNAme: Description: Application Load Balancer DNS Name Value: !GetAtt RailsLoadBalancer.DNSName RailsFunctionArn: Description: Lambda ARN Value: !GetAtt RailsFunction.Arn