Skip to content

Commit ca54b9c

Browse files
committed
feat: added tests and adjusted readme
1 parent 15e742b commit ca54b9c

File tree

2 files changed

+172
-5
lines changed

2 files changed

+172
-5
lines changed

README.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
![serverless](http://public.serverless.com/badges/v3.svg)
2-
[![Build Status](https://travis-ci.org/horike37/serverless-apigateway-service-proxy.svg?branch=master)](https://travis-ci.org/horike37/serverless-apigateway-service-proxy) [![npm version](https://badge.fury.io/js/serverless-apigateway-service-proxy.svg)](https://badge.fury.io/js/serverless-apigateway-service-proxy) [![Coverage Status](https://coveralls.io/repos/github/horike37/serverless-apigateway-service-proxy/badge.svg?branch=master)](https://coveralls.io/github/horike37/serverless-apigateway-service-proxy?branch=master) [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
1+
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)
32

43
# Serverless APIGateway Service Proxy
54

65
This Serverless Framework plugin supports the AWS service proxy integration feature of API Gateway. You can directly connect API Gateway to AWS services without Lambda.
6+
In addition this fork support customized Path overrides to cater more specialized use cases.
77

88
## Install
99

10-
Run `serverless plugin install` in your Serverless project.
10+
Run `yarn add @hans_seek/serverless-apigateway-service-proxy` to install the plugin
1111

1212
```bash
13-
serverless plugin install -n @hans_seek/serverless-apigateway-service-proxy
13+
yarn add @hans_seek/serverless-apigateway-service-proxy
1414
```
1515

16-
Alternative run (if previous fails) `yarn add @hans_seek/serverless-apigateway-service-proxy`
16+
Or if using NPM:
17+
18+
```bash
19+
npm i @hans_seek/serverless-apigateway-service-proxy --save
20+
```
1721

1822
## Supported AWS services
1923

@@ -27,6 +31,13 @@ Please pull request if you are intersted in it.
2731

2832
## How to use
2933

34+
Add the Plugin to your `serverless.yml`
35+
36+
```yaml
37+
plugins:
38+
- '@hans_seek/serverless-apigateway-service-proxy'
39+
```
40+
3041
Define settings of the AWS services you want to integrate under `custom > apiGatewayServiceProxies` and run `serverless deploy`.
3142

3243
### Kinesis
@@ -199,6 +210,38 @@ custom:
199210
'integration.request.header.cache-control': "'public, max-age=31536000, immutable'"
200211
```
201212

213+
#### Customize the Path Override in API Gateway
214+
215+
Added the new customization parameter that lets the user set a custom Path Override in API Gateway other than the `{bucket}/{object}`
216+
This parameter is optional and if not set, will fall back to `{bucket}/{object}`
217+
The Path Override will add `{bucket}/` automatically in front
218+
219+
Please keep in mind, that key or path.object still needs to be set at the moment (maybe this will be made optional later on with this)
220+
221+
Usage (With 2 Path Parameters (folder and file and a fixed file extension)):
222+
223+
```yaml
224+
custom:
225+
apiGatewayServiceProxies:
226+
- s3:
227+
path: /s3/{folder}/{file}
228+
method: get
229+
action: GetObject
230+
pathoverride: '{folder}/{file}.xml'
231+
bucket:
232+
Ref: S3Bucket
233+
cors: true
234+
235+
requestParameters:
236+
# if requestParameters has a 'integration.request.path.object' property you should remove the key setting
237+
'integration.request.path.folder': 'method.request.path.folder'
238+
'integration.request.path.file': 'method.request.path.file'
239+
'integration.request.path.object': 'context.requestId'
240+
'integration.request.header.cache-control': "'public, max-age=31536000, immutable'"
241+
```
242+
This will result in API Gateway setting the Path Override attribute to `{bucket}/{folder}/{file}.xml`
243+
So for example if you navigate to the API Gatway endpoint `/language/en` it will fetch the file in S3 from `{bucket}/language/en.xml`
244+
202245
### SNS
203246

204247
Sample syntax for SNS proxy in `serverless.yml`.

lib/package/s3/compileMethodsToS3.test.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,4 +681,128 @@ describe('#compileMethodsToS3()', () => {
681681
'method.request.path.key': true
682682
})
683683
})
684+
685+
it('should create corresponding resources when s3 GetObject proxy is given with path override', () => {
686+
serverlessApigatewayServiceProxy.validated = {
687+
events: [
688+
{
689+
serviceName: 's3',
690+
http: {
691+
path: '/{folder}/{item}',
692+
method: 'get',
693+
bucket: {
694+
Ref: 'MyBucket'
695+
},
696+
action: 'GetObject',
697+
key: {
698+
pathParam: 'item'
699+
},
700+
pathoverride: '{folder}/{item}.xml',
701+
auth: { authorizationType: 'NONE' },
702+
requestParameters: {
703+
'integration.request.path.folder': 'method.request.path.folder',
704+
'integration.request.path.item': 'method.request.path.item'
705+
}
706+
}
707+
}
708+
]
709+
}
710+
serverlessApigatewayServiceProxy.apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
711+
serverlessApigatewayServiceProxy.apiGatewayResources = {
712+
'/{folder}/{item}': {
713+
name: 'po',
714+
resourceLogicalId: 'ApiGatewayPathOverrideS3'
715+
}
716+
}
717+
718+
serverlessApigatewayServiceProxy.compileMethodsToS3()
719+
expect(serverless.service.provider.compiledCloudFormationTemplate.Resources).to.deep.equal({
720+
ApiGatewayMethodpoGet: {
721+
Type: 'AWS::ApiGateway::Method',
722+
Properties: {
723+
HttpMethod: 'GET',
724+
RequestParameters: {
725+
'method.request.path.folder': true,
726+
'method.request.path.item': true
727+
},
728+
AuthorizationType: 'NONE',
729+
AuthorizationScopes: undefined,
730+
AuthorizerId: undefined,
731+
ApiKeyRequired: false,
732+
ResourceId: { Ref: 'ApiGatewayPathOverrideS3' },
733+
RestApiId: { Ref: 'ApiGatewayRestApi' },
734+
Integration: {
735+
Type: 'AWS',
736+
IntegrationHttpMethod: 'GET',
737+
Credentials: { 'Fn::GetAtt': ['ApigatewayToS3Role', 'Arn'] },
738+
Uri: {
739+
'Fn::Sub': [
740+
'arn:aws:apigateway:${AWS::Region}:s3:path/{bucket}/{folder}/{item}.xml',
741+
{}
742+
]
743+
},
744+
PassthroughBehavior: 'WHEN_NO_MATCH',
745+
RequestParameters: {
746+
'integration.request.path.bucket': {
747+
'Fn::Sub': [
748+
"'${bucket}'",
749+
{
750+
bucket: {
751+
Ref: 'MyBucket'
752+
}
753+
}
754+
]
755+
},
756+
'integration.request.path.object': 'method.request.path.item',
757+
'integration.request.path.folder': 'method.request.path.folder',
758+
'integration.request.path.item': 'method.request.path.item'
759+
},
760+
IntegrationResponses: [
761+
{
762+
StatusCode: 400,
763+
SelectionPattern: '4\\d{2}',
764+
ResponseParameters: {},
765+
ResponseTemplates: {}
766+
},
767+
{
768+
StatusCode: 500,
769+
SelectionPattern: '5\\d{2}',
770+
ResponseParameters: {},
771+
ResponseTemplates: {}
772+
},
773+
{
774+
StatusCode: 200,
775+
SelectionPattern: '2\\d{2}',
776+
ResponseParameters: {
777+
'method.response.header.Content-Type': 'integration.response.header.Content-Type',
778+
'method.response.header.content-type': 'integration.response.header.content-type'
779+
},
780+
ResponseTemplates: {}
781+
}
782+
]
783+
},
784+
MethodResponses: [
785+
{
786+
ResponseParameters: {
787+
'method.response.header.Content-Type': true,
788+
'method.response.header.content-type': true
789+
},
790+
ResponseModels: {},
791+
StatusCode: 200
792+
},
793+
{
794+
ResponseParameters: {},
795+
ResponseModels: {},
796+
StatusCode: 400
797+
},
798+
{
799+
ResponseParameters: {},
800+
ResponseModels: {},
801+
StatusCode: 500
802+
}
803+
]
804+
}
805+
}
806+
})
807+
})
684808
})

0 commit comments

Comments
 (0)