|
| 1 | +AWSTemplateFormatVersion: '2010-09-09' |
| 2 | +Transform: AWS::Serverless-2016-10-31 |
| 3 | +Description: Multi-source API Lambda function with ALB and API Gateway V2 |
| 4 | +Resources: |
| 5 | + MultiSourceAPIFunction: |
| 6 | + Type: AWS::Serverless::Function |
| 7 | + Properties: |
| 8 | + CodeUri: ../../.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MultiSourceAPI/MultiSourceAPI.zip |
| 9 | + Handler: provided |
| 10 | + Runtime: provided.al2 |
| 11 | + Architectures: |
| 12 | + - arm64 |
| 13 | + MemorySize: 256 |
| 14 | + Timeout: 30 |
| 15 | + Environment: |
| 16 | + Variables: |
| 17 | + LOG_LEVEL: trace |
| 18 | + Events: |
| 19 | + ApiGatewayEvent: |
| 20 | + Type: HttpApi |
| 21 | + Properties: |
| 22 | + Path: /{proxy+} |
| 23 | + Method: ANY |
| 24 | + VPC: |
| 25 | + Type: AWS::EC2::VPC |
| 26 | + Properties: |
| 27 | + CidrBlock: 10.0.0.0/16 |
| 28 | + EnableDnsHostnames: true |
| 29 | + EnableDnsSupport: true |
| 30 | + PublicSubnet1: |
| 31 | + Type: AWS::EC2::Subnet |
| 32 | + Properties: |
| 33 | + VpcId: |
| 34 | + Ref: VPC |
| 35 | + CidrBlock: 10.0.1.0/24 |
| 36 | + AvailabilityZone: |
| 37 | + Fn::Select: |
| 38 | + - 0 |
| 39 | + - Fn::GetAZs: '' |
| 40 | + MapPublicIpOnLaunch: true |
| 41 | + PublicSubnet2: |
| 42 | + Type: AWS::EC2::Subnet |
| 43 | + Properties: |
| 44 | + VpcId: |
| 45 | + Ref: VPC |
| 46 | + CidrBlock: 10.0.2.0/24 |
| 47 | + AvailabilityZone: |
| 48 | + Fn::Select: |
| 49 | + - 1 |
| 50 | + - Fn::GetAZs: '' |
| 51 | + MapPublicIpOnLaunch: true |
| 52 | + InternetGateway: |
| 53 | + Type: AWS::EC2::InternetGateway |
| 54 | + AttachGateway: |
| 55 | + Type: AWS::EC2::VPCGatewayAttachment |
| 56 | + Properties: |
| 57 | + VpcId: |
| 58 | + Ref: VPC |
| 59 | + InternetGatewayId: |
| 60 | + Ref: InternetGateway |
| 61 | + RouteTable: |
| 62 | + Type: AWS::EC2::RouteTable |
| 63 | + Properties: |
| 64 | + VpcId: |
| 65 | + Ref: VPC |
| 66 | + Route: |
| 67 | + Type: AWS::EC2::Route |
| 68 | + DependsOn: AttachGateway |
| 69 | + Properties: |
| 70 | + RouteTableId: |
| 71 | + Ref: RouteTable |
| 72 | + DestinationCidrBlock: '0.0.0.0/0' |
| 73 | + GatewayId: |
| 74 | + Ref: InternetGateway |
| 75 | + SubnetRouteTableAssociation1: |
| 76 | + Type: AWS::EC2::SubnetRouteTableAssociation |
| 77 | + Properties: |
| 78 | + SubnetId: |
| 79 | + Ref: PublicSubnet1 |
| 80 | + RouteTableId: |
| 81 | + Ref: RouteTable |
| 82 | + SubnetRouteTableAssociation2: |
| 83 | + Type: AWS::EC2::SubnetRouteTableAssociation |
| 84 | + Properties: |
| 85 | + SubnetId: |
| 86 | + Ref: PublicSubnet2 |
| 87 | + RouteTableId: |
| 88 | + Ref: RouteTable |
| 89 | + ALBSecurityGroup: |
| 90 | + Type: AWS::EC2::SecurityGroup |
| 91 | + Properties: |
| 92 | + GroupDescription: Security group for ALB |
| 93 | + VpcId: |
| 94 | + Ref: VPC |
| 95 | + SecurityGroupIngress: |
| 96 | + - IpProtocol: tcp |
| 97 | + FromPort: 80 |
| 98 | + ToPort: 80 |
| 99 | + CidrIp: '0.0.0.0/0' |
| 100 | + ApplicationLoadBalancer: |
| 101 | + Type: AWS::ElasticLoadBalancingV2::LoadBalancer |
| 102 | + Properties: |
| 103 | + Scheme: internet-facing |
| 104 | + Subnets: |
| 105 | + - Ref: PublicSubnet1 |
| 106 | + - Ref: PublicSubnet2 |
| 107 | + SecurityGroups: |
| 108 | + - Ref: ALBSecurityGroup |
| 109 | + ALBTargetGroup: |
| 110 | + Type: AWS::ElasticLoadBalancingV2::TargetGroup |
| 111 | + DependsOn: ALBLambdaInvokePermission |
| 112 | + Properties: |
| 113 | + TargetType: lambda |
| 114 | + Targets: |
| 115 | + - Id: |
| 116 | + Fn::GetAtt: |
| 117 | + - MultiSourceAPIFunction |
| 118 | + - Arn |
| 119 | + ALBListener: |
| 120 | + Type: AWS::ElasticLoadBalancingV2::Listener |
| 121 | + Properties: |
| 122 | + LoadBalancerArn: |
| 123 | + Ref: ApplicationLoadBalancer |
| 124 | + Port: 80 |
| 125 | + Protocol: HTTP |
| 126 | + DefaultActions: |
| 127 | + - Type: forward |
| 128 | + TargetGroupArn: |
| 129 | + Ref: ALBTargetGroup |
| 130 | + ALBLambdaInvokePermission: |
| 131 | + Type: AWS::Lambda::Permission |
| 132 | + Properties: |
| 133 | + FunctionName: |
| 134 | + Fn::GetAtt: |
| 135 | + - MultiSourceAPIFunction |
| 136 | + - Arn |
| 137 | + Action: lambda:InvokeFunction |
| 138 | + Principal: elasticloadbalancing.amazonaws.com |
| 139 | +Outputs: |
| 140 | + ApiGatewayUrl: |
| 141 | + Description: API Gateway endpoint URL |
| 142 | + Value: |
| 143 | + Fn::Sub: https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com |
| 144 | + ALBUrl: |
| 145 | + Description: Application Load Balancer URL |
| 146 | + Value: |
| 147 | + Fn::Sub: http://${ApplicationLoadBalancer.DNSName} |
0 commit comments