Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save veve90/8ac5b5dd7913a280f321f3dcadf66155 to your computer and use it in GitHub Desktop.

Select an option

Save veve90/8ac5b5dd7913a280f321f3dcadf66155 to your computer and use it in GitHub Desktop.

Revisions

  1. @Pelirrojo Pelirrojo created this gist Jan 17, 2019.
    63 changes: 63 additions & 0 deletions apigateway-proxy-cloudformation-template.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    # LICENSE https://creativecommons.org/licenses/by-nc-sa/3.0/
    # https://cjohansen.no/aws-apigw-proxy-cloudformation/

    AWSTemplateFormatVersion: 2010-09-09
    Description: An API that proxies requests to another HTTP endpoint

    Resources:
    Api:
    Type: 'AWS::ApiGateway::RestApi'
    Properties:
    Name: SomeProxyApi

    Resource:
    Type: 'AWS::ApiGateway::Resource'
    Properties:
    ParentId: !GetAtt Api.RootResourceId
    RestApiId: !Ref Api
    PathPart: '{proxy+}'

    RootMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
    HttpMethod: ANY
    ResourceId: !GetAtt Api.RootResourceId
    RestApiId: !Ref Api
    AuthorizationType: NONE
    Integration:
    IntegrationHttpMethod: ANY
    Type: HTTP_PROXY
    Uri: http://my-imaginary-bucket.s3-website-eu-west-1.amazonaws.com/
    PassthroughBehavior: WHEN_NO_MATCH
    IntegrationResponses:
    - StatusCode: 200

    ProxyMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
    HttpMethod: ANY
    ResourceId: !Ref Resource
    RestApiId: !Ref Api
    AuthorizationType: NONE
    RequestParameters:
    method.request.path.proxy: true
    Integration:
    CacheKeyParameters:
    - 'method.request.path.proxy'
    RequestParameters:
    integration.request.path.proxy: 'method.request.path.proxy'
    IntegrationHttpMethod: ANY
    Type: HTTP_PROXY
    Uri: http://my-imaginary-bucket.s3-website-eu-west-1.amazonaws.com/{proxy}
    PassthroughBehavior: WHEN_NO_MATCH
    IntegrationResponses:
    - StatusCode: 200

    Deployment:
    DependsOn:
    - RootMethod
    - ProxyMethod
    Type: 'AWS::ApiGateway::Deployment'
    Properties:
    RestApiId: !Ref Api
    StageName: !Ref StageName
    13 changes: 13 additions & 0 deletions script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/usr/bin/env bash

    H1='\033[96m' # Light Cyan
    OK='\033[0;32m' # Green
    NC='\033[0m' # No Color

    jq --version >/dev/null 2>&1 || { echo >&2 "I require jq utility but it's not installed. Aborting."; exit 1; }
    aws --version >/dev/null 2>&1 || { echo >&2 "I require AWS CLI utility but it's not installed. Aborting."; exit 1; }

    export EXPORT_VALUE=`aws cloudformation list-exports | jq .Exports | jq -r -c '.[] | select(.Name | contains("LogicExportID")).Value'`
    export OUTPUT_VALUE="$(aws cloudformation describe-stacks --stack-name my-stack --region eu-west-1 --query 'Stacks[0].Outputs[?OutputKey==`RestApi`].OutputValue' --output text)"

    aws cloudformation deploy --template-file apigateway-proxy-cloudformation-template.yaml --stack-name api-proxy-demo2 --parameter-overrides LBUri=$LB_URI