Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
fix s3 proxy deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeschwendt committed Nov 21, 2018
1 parent 634d133 commit b3560b9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
47 changes: 47 additions & 0 deletions .serverless_plugins/serverless-patches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict'

class ServerlessPlugin {
constructor(serverless, options) {
this.serverless = serverless
this.options = options

this.hooks = {
'before:package:finalize': this.beforePackageFinalize.bind(this),
}
}

beforePackageFinalize () {
const Resources = this.serverless.service.provider.compiledCloudFormationTemplate.Resources

// Add caching to ApiGatewayMethodProxyVarGet
Object.keys(Resources).map(key => {
if (key === 'ApiGatewayMethodProxyVarGet') {
Resources[key].Properties = {
...Resources[key].Properties,
Integration: {
...Resources[key].Properties.Integration,
CacheKeyParameters: ['method.request.path.proxy'],
CacheNamespace: 'ApiGatewayMethodProxyVarGetCacheNS',
RequestParameters: {
'integration.request.path.proxy': 'method.request.path.proxy'
}
},
RequestParameters: {
...Resources[key].Properties.RequestParameters,
'method.request.path.proxy': true
}
}
}

// Add S3 Proxy API Method to the API Gateway Deployment dependencies
if (key.indexOf('ApiGatewayDeployment') > -1) {
Resources[key].DependsOn = [
...Resources[key].DependsOn,
'ApiGatewayMethodStaticProxyVarGet'
]
}
})
}
}

module.exports = ServerlessPlugin
52 changes: 1 addition & 51 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins:
- serverless-finch
- serverless-webpack # https://github.com/serverless-heaven/serverless-webpack#usage-with-serverless-offline
- serverless-offline
- serverless-patches

provider:
name: aws
Expand Down Expand Up @@ -48,58 +49,7 @@ functions:
path: /{proxy+}

resources:
Mappings:
# http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints
RegionMap:
ap-northeast-1:
S3HostedZoneId: Z2M4EHUR26P7ZW
S3WebsiteEndpoint: s3-website-ap-northeast-1.amazonaws.com
ap-northeast-2:
S3HostedZoneId: Z3W03O7B5YMIYP
S3WebsiteEndpoint: s3-website.ap-northeast-2.amazonaws.com
ap-south-1:
S3HostedZoneId: Z11RGJOFQNVJUP
S3WebsiteEndpoint: s3-website.ap-south-1.amazonaws.com
ap-southeast-1:
S3HostedZoneId: Z3O0J2DXBE1FTB
S3WebsiteEndpoint: s3-website-ap-southeast-1.amazonaws.com
ap-southeast-2:
S3HostedZoneId: Z1WCIGYICN2BYD
S3WebsiteEndpoint: s3-website-ap-southeast-2.amazonaws.com
eu-central-1:
S3HostedZoneId: Z21DNDUVLTQW6Q
S3WebsiteEndpoint: s3-website.eu-central-1.amazonaws.com
eu-west-1:
S3HostedZoneId: Z1BKCTXD74EZPE
S3WebsiteEndpoint: s3-website-eu-west-1.amazonaws.com
sa-east-1:
S3HostedZoneId: Z7KQH4QJS55SO
S3WebsiteEndpoint: s3-website-sa-east-1.amazonaws.com
us-east-1:
S3HostedZoneId: Z3AQBSTGFYJSTF
S3WebsiteEndpoint: s3-website-us-east-1.amazonaws.com
us-east-2:
S3HostedZoneId: Z2O1EMRO9K5GLX
S3WebsiteEndpoint: s3-website.us-east-2.amazonaws.com
us-west-1:
S3HostedZoneId: Z2F56UZL2M1ACD
S3WebsiteEndpoint: s3-website-us-west-1.amazonaws.com
us-west-2:
S3HostedZoneId: Z3BJ6K6RIION7M
S3WebsiteEndpoint: s3-website-us-west-2.amazonaws.com

Resources:
ApiGatewayMethodProxyVarGet:
Properties:
Integration:
CacheKeyParameters:
- method.request.path.proxy
CacheNamespace: ApiGatewayMethodProxyVarGetCacheNS
RequestParameters:
integration.request.path.proxy: method.request.path.proxy
RequestParameters:
method.request.path.proxy: true

ApiGatewayBasePathMapping:
DependsOn: ApiGatewayDomainName
Type: AWS::ApiGateway::BasePathMapping
Expand Down

0 comments on commit b3560b9

Please sign in to comment.