Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pelirrojo/cb5d32854b88cc712a248c357ffa04f4 to your computer and use it in GitHub Desktop.
Save Pelirrojo/cb5d32854b88cc712a248c357ffa04f4 to your computer and use it in GitHub Desktop.
A Cloudformation Script to deploy an API Gateway Proxy
# 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
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment