Skip to content

Commit

Permalink
Updating API Gateway template from AWS docs, updating SNS template to…
Browse files Browse the repository at this point in the history
… use empty strings instead of nulls. Moving imports outside of dictionary so TS will include them in the dist
  • Loading branch information
astuyve committed Apr 17, 2019
1 parent b48d106 commit 2ebdfee
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 37 deletions.
78 changes: 50 additions & 28 deletions lib/events/aws/api-gateway-event-template.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
{
"body": {},
"method": "GET",
"principalId": "",
"stage": "dev",
"body": "",
"path": "/test/hello",
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-us",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, lzma, sdch, br",
"Accept-Language": "en-US,en;q=0.8",
"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": "US",
"Cookie": "__gads=ID=d51d609e5753330d:T=1443694116:S=ALNI_MbjWKzLwdEpWZ5wR5WXRI2dtjIpHw; __qca=P0-179798513-1443694132017; _ga=GA1.2.344061584.1441769647",
"Host": "xxx.execute-api.us-east-1.amazonaws.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17",
"Via": "1.1 c8a5bb0e20655459eaam174e5c41443b.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "z7Ds7oXaY8hgUn7lcedZjoIoxyvnzF6ycVzBdQmhn3QnOPEjJz4BrQ==",
"X-Forwarded-For": "221.24.103.21, 54.242.148.216",
"Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
"Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)",
"X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==",
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
"X-Forwarded-Port": "443",
"X-Forwarded-Proto": "https"
},
"query": {},
"path": {},
"identity": {
"cognitoIdentityPoolId": "",
"accountId": "",
"cognitoIdentityId": "",
"caller": "",
"apiKey": "",
"sourceIp": "221.24.103.21",
"cognitoAuthenticationType": "",
"cognitoAuthenticationProvider": "",
"userArn": "",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/601.6.17 (KHTML, like Gecko) Version/9.1.1 Safari/601.6.17",
"user": ""
"pathParameters": {
"proxy": "hello"
},
"stageVariables": {}
"multiValueHeaders": {},
"isBase64Encoded": false,
"multiValueQueryStringParameters": {},
"requestContext": {
"accountId": "123456789012",
"resourceId": "us4z18",
"stage": "test",
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
"identity": {
"accessKey": "",
"apiKeyId": "",
"cognitoIdentityPoolId": "",
"accountId": "",
"cognitoIdentityId": "",
"caller": "",
"apiKey": "",
"sourceIp": "192.168.100.1",
"cognitoAuthenticationType": "",
"cognitoAuthenticationProvider": "",
"userArn": "",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
"user": ""
},
"path": "",
"requestTimeEpoch": 0,
"resourcePath": "/{proxy+}",
"httpMethod": "GET",
"apiId": "wt6mne2s9k"
},
"resource": "/{proxy+}",
"httpMethod": "GET",
"queryStringParameters": {
"name": "me"
},
"stageVariables": {
"stageVarName": "stageVarValue"
}
}
2 changes: 1 addition & 1 deletion lib/events/aws/sns-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Type": "Notification",
"MessageId": "52ed5e3d-5fgf-56bf-923d-0e5c3b503c2a",
"TopicArn": "arn:aws:sns:us-east-1:123456789:service-1474781718017-1",
"Subject": null,
"Subject": "",
"Message": "hello world",
"Timestamp": "2016-09-25T05:37:51.150Z",
"SignatureVersion": "1",
Expand Down
2 changes: 1 addition & 1 deletion lib/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('createApigEvent()', () => {

expect(event.body.first_name).to.equal('Sam')
expect(event.body.last_name).to.equal('Smith')
expect(event.method).to.equal('GET')
expect(event.httpMethod).to.equal('GET')
})
})

Expand Down
21 changes: 14 additions & 7 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { merge, cloneDeep } from 'lodash'
import { APIGatewayEvent, ScheduledEvent, S3Event, KinesisStreamEvent, DynamoDBStreamEvent, SQSEvent, SNSEvent } from 'aws-lambda'
import { GeneratedEvent } from './generatedEvent'
import snsTemplate from './events/aws/sns-template.json'
import sqsTemplate from './events/aws/sqs-template.json'
import apiGatewayTemplate from './events/aws/api-gateway-event-template.json'
import scheduledTemplate from './events/aws/scheduled-template.json'
import s3Template from './events/aws/s3-template.json'
import kinesisTemplate from './events/aws/kinesis-template.json'
import dynamoTemplate from './events/aws/dynamo-stream-event-template.json'

const dictionary: any = {
'aws:sns': require('./events/aws/sns-template.json') as SNSEvent,
'aws:sqs': require('./events/aws/sqs-template.json') as SQSEvent,
'aws:apiGateway': require('./events/aws/api-gateway-event-template.json') as APIGatewayEvent,
'aws:scheduled': require('./events/aws/scheduled-template.json') as ScheduledEvent,
'aws:s3': require('./events/aws/s3-template.json') as S3Event,
'aws:kinesis': require('./events/aws/kinesis-template.json') as KinesisStreamEvent,
'aws:dynamo': require('./events/aws/dynamo-stream-event-template.json') as DynamoDBStreamEvent,
'aws:sns': snsTemplate as SNSEvent,
'aws:sqs': sqsTemplate as SQSEvent,
'aws:apiGateway': apiGatewayTemplate as APIGatewayEvent,
'aws:scheduled': scheduledTemplate as ScheduledEvent,
'aws:s3': s3Template as S3Event,
'aws:kinesis': kinesisTemplate as KinesisStreamEvent,
'aws:dynamo': dynamoTemplate as DynamoDBStreamEvent,
}

export default function createEvent(eventType: string, body: any): GeneratedEvent {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"outDir": "./dist",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
},
}

0 comments on commit 2ebdfee

Please sign in to comment.