Created
February 4, 2019 14:05
-
-
Save maciejmajewski/15b47a3da2329072190bcc1bbb922a42 to your computer and use it in GitHub Desktop.
AWS API Gateway HTTP proxy CloudFormation template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: 2010-09-09 | |
Parameters: | |
HostName: | |
Type: String | |
Description: Name of the instance, in host-friendly name - underscored. Will be concatenated into .on-pulse.com domain | |
ProxyHost: | |
Type: String | |
Description: Host that should be proxied | |
HostedZoneName: | |
Type: String | |
Description: "Zone for domain" | |
Default: "on-pulse.com" | |
Resources: | |
APIGateway: | |
Type: "AWS::ApiGateway::RestApi" | |
Properties: | |
Name: !Join ['-', [!Ref 'HostName', 'proxy']] | |
Description: !Join ['', [!Ref 'HostName', '.on-pulse.com proxy to ', !Ref ProxyHost]] | |
BinaryMediaTypes: | |
- 'application/font-woff' | |
- 'application/vnd.ms-fontobject' | |
- 'font/ttf' | |
- 'image/png' | |
- 'image/jpg' | |
- 'image/jpeg' | |
- 'image/vnd.microsoft.icon' | |
- 'application/zip' | |
- 'application/vnd.ms-excel' | |
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' | |
APIGatewayRootMethod: | |
Type: "AWS::ApiGateway::Method" | |
Properties: | |
RestApiId: !Ref APIGateway | |
ResourceId: !GetAtt [APIGateway, RootResourceId] | |
HttpMethod: "ANY" | |
AuthorizationType: "NONE" | |
Integration: | |
Type: "HTTP_PROXY" | |
IntegrationHttpMethod: "ANY" | |
Uri: !Join ['', ['https://', !Ref ProxyHost]] | |
APIGatewayProxyResource: | |
Type: "AWS::ApiGateway::Resource" | |
Properties: | |
RestApiId: !Ref APIGateway | |
ParentId: !GetAtt [APIGateway, RootResourceId] | |
PathPart: "{proxy+}" | |
APIGatewayProxyMethod: | |
Type: "AWS::ApiGateway::Method" | |
Properties: | |
RestApiId: !Ref APIGateway | |
ResourceId: !Ref APIGatewayProxyResource | |
HttpMethod: "ANY" | |
AuthorizationType: "NONE" | |
RequestParameters: | |
method.request.path.proxy: true | |
Integration: | |
Type: "HTTP_PROXY" | |
IntegrationHttpMethod: "ANY" | |
Uri: !Join ['', ['https://', !Ref ProxyHost, '/{proxy}']] | |
CacheKeyParameters: | |
- 'method.request.path.proxy' | |
RequestParameters: | |
integration.request.path.proxy: 'method.request.path.proxy' | |
MethodResponses: | |
- StatusCode: 200 | |
ResponseParameters: | |
method.response.header.Content-Type: true | |
APIGatewayDeployment: | |
Type: "AWS::ApiGateway::Deployment" | |
DependsOn: | |
- "APIGatewayRootMethod" | |
Properties: | |
RestApiId: !Ref APIGateway | |
StageName: "production" | |
GatewayDomain: | |
Type: "AWS::ApiGateway::DomainName" | |
Properties: | |
DomainName: !Join ['', [!Ref 'HostName', '.', !Ref 'HostedZoneName']] | |
EndpointConfiguration: | |
Types: | |
- REGIONAL | |
RegionalCertificateArn: arn:aws:acm:eu-central-1:694314498149:certificate/783c33a8-bc33-43f0-ab9d-800a0f1d59b1 | |
PathMapping: | |
Type: "AWS::ApiGateway::BasePathMapping" | |
DependsOn: | |
- "APIGatewayDeployment" | |
Properties: | |
RestApiId: !Ref APIGateway | |
DomainName: !Join ['', [!Ref 'HostName', '.', !Ref 'HostedZoneName']] | |
Stage: "production" | |
OnPulseHost: | |
Type: AWS::Route53::RecordSet | |
Properties: | |
HostedZoneName: !Join ['', [!Ref 'HostedZoneName', '.']] | |
Name: !Join ['', [!Ref 'HostName', '.', !Ref 'HostedZoneName', '.']] | |
Type: "A" | |
AliasTarget: | |
DNSName: !GetAtt GatewayDomain.RegionalDomainName | |
HostedZoneId: "Z1U9ULNL0V5AJ3" | |
Outputs: | |
ProxyURL: | |
Description: on-pulse.com URL for proxy instance | |
Value: !Join ['', ['https://', !Ref 'HostName', '.', !Ref 'HostedZoneName']] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment