-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support sls default custom mapping template
Adds support for the serverless framework legacy `lambda` integration which uses custom-mapping templates instead of the now-default lambda-proxy. This input type uses the ApiGateway event type fields as the meaning is similar, although only a subset of those fields are supported by this event type. Signed-off-by: Erica Windisch <73207+ewindisch@users.noreply.github.com> Co-authored-by: Corey Light <coreylight@gmail.com>
- Loading branch information
1 parent
b34551a
commit 2033c3e
Showing
8 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import apiGateway from './apiGateway'; | ||
import slsIntegrationLambda from './slsIntegrationLambda'; | ||
import cloudFront from './cloudFront'; | ||
import firehose from './firehose'; | ||
import kinesis from './kinesis'; | ||
import s3 from './s3'; | ||
import scheduled from './scheduled'; | ||
import sns from './sns'; | ||
|
||
export { apiGateway, cloudFront, firehose, kinesis, s3, scheduled, sns }; | ||
export { | ||
apiGateway, | ||
slsIntegrationLambda, | ||
cloudFront, | ||
firehose, | ||
kinesis, | ||
s3, | ||
scheduled, | ||
sns | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
export default { | ||
body: {}, | ||
method: 'GET', | ||
principalId: '1234', | ||
stage: 'dev', | ||
cognitoPoolClaims: { | ||
sub: '' | ||
}, | ||
enhancedAuthContext: {}, | ||
headers: { | ||
Accept: | ||
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', | ||
'Accept-Encoding': 'gzip, deflate, br', | ||
'Accept-Language': 'en-GB,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4', | ||
'CloudFront-Forwarded-Proto': 'https', | ||
'CloudFront-Is-Desktop-Viewer': 'true', | ||
'CloudFront-Is-Mobile-Viewer': 'false', | ||
'CloudFront-Is-SmartTV-Viewer': 'false', | ||
'CloudFront-Is-Tablet-Viewer': 'false', | ||
'CloudFront-Viewer-Country': 'GB', | ||
Host: 'ec5ycylws8.execute-api.us-east-1.amazonaws.com', | ||
'upgrade-insecure-requests': '1', | ||
'User-Agent': | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', | ||
Via: '2.0 f165ce34daf8c0da182681179e863c24.cloudfront.net (CloudFront)', | ||
'X-Amz-Cf-Id': 'l06CAg2QsrALeQcLAUSxGXbm8lgMoMIhR2AjKa4AiKuaVnnGsOFy5g==', | ||
'X-Amzn-Trace-Id': 'Root=1-5970ef3e249c0321b2eef14aa513ae', | ||
'X-Forwarded-For': '94.117.120.169, 116.132.62.73', | ||
'X-Forwarded-Port': '443', | ||
'X-Forwarded-Proto': 'https' | ||
}, | ||
query: {}, | ||
path: {}, | ||
identity: { | ||
cognitoIdentityPoolId: '', | ||
accountId: '1234', | ||
cognitoIdentityId: '', | ||
caller: '', | ||
apiKey: '', | ||
sourceIp: '94.197.120.169', | ||
accessKey: '', | ||
cognitoAuthenticationType: '', | ||
cognitoAuthenticationProvider: '', | ||
userArn: '', | ||
userAgent: | ||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', | ||
user: '' | ||
}, | ||
stageVariables: {} | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
import * as apiGateway from './apiGateway'; | ||
import * as slsIntegrationLambda from './slsIntegrationLambda'; | ||
import * as cloudFront from './cloudFront'; | ||
import * as firehose from './firehose'; | ||
import * as kinesis from './kinesis'; | ||
import * as s3 from './s3'; | ||
import * as scheduled from './scheduled'; | ||
import * as sns from './sns'; | ||
|
||
export { apiGateway, cloudFront, firehose, kinesis, s3, scheduled, sns }; | ||
export { | ||
apiGateway, | ||
slsIntegrationLambda, | ||
cloudFront, | ||
firehose, | ||
kinesis, | ||
s3, | ||
scheduled, | ||
sns | ||
}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import get from 'lodash.get'; | ||
|
||
import logFromKeys from '../util/logFromKeys'; | ||
import { pluginName } from '../util/constants'; | ||
|
||
/* This module supports the "lambda" type integration | ||
for the serverless framework which provides a | ||
default custom mapping template. | ||
The sls mapping template is described here: | ||
https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-event-before-customization | ||
*/ | ||
|
||
const type = 'apiGateway'; | ||
const source = 'slsIntegrationLambda'; | ||
|
||
const keys = ['body', 'method', 'principalId', 'stage']; | ||
|
||
const keysThatNeedValues = [ | ||
'identity.userAgent', | ||
'identity.sourceIp', | ||
'identity.accountId' | ||
]; | ||
|
||
function eventType(event) { | ||
if (typeof event === 'object') { | ||
const keysArePresent = keys.every(s => s in event); | ||
const valuesArePresent = | ||
keysThatNeedValues | ||
.map(k => { | ||
return typeof get(event, k) !== 'undefined'; | ||
}) | ||
.filter(Boolean).length === keysThatNeedValues.length; | ||
return keysArePresent && valuesArePresent ? source : false; | ||
} | ||
return false; | ||
} | ||
|
||
const pluginKeyMapping = [ | ||
['method', 'httpMethod'], | ||
['identity.accountId', 'requestContext.accountId'], | ||
['method', 'requestContext.httpMethod'], | ||
['identity.userAgent', 'requestContext.identity.userAgent'], | ||
['stage', 'requestContext.stage'], | ||
'headers.X-Amz-Cf-Id', | ||
'headers.X-Amzn-Trace-Id' | ||
]; | ||
|
||
function plugin(event, log) { | ||
logFromKeys({ event, type, keys: pluginKeyMapping, log }); | ||
log(`${pluginName}.eventType.source`, source); | ||
} | ||
|
||
export { eventType, plugin }; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/*eslint-disable import/prefer-default-export*/ | ||
const pluginName = '@iopipe/event-info'; | ||
|
||
export { pluginName }; |
This file contains 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
This file contains 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