File tree Expand file tree Collapse file tree 3 files changed +99
-1
lines changed
integration/dynamodb/single-integration Expand file tree Collapse file tree 3 files changed +99
-1
lines changed Original file line number Diff line number Diff line change 1+ service : dynamodb-proxy
2+
3+ provider :
4+ name : aws
5+ runtime : nodejs10.x
6+
7+ plugins :
8+ localPath : ' ./../../../../../../'
9+ modules :
10+ - serverless-apigateway-service-proxy
11+
12+ custom :
13+ apiGatewayServiceProxies :
14+ - dynamodb :
15+ path : /dynamodb
16+ method : post
17+ tableName :
18+ Ref : MyTestTable
19+ hashKey : ' id'
20+ cors : true
21+
22+ resources :
23+ Resources :
24+ MyTestTable :
25+ Type : AWS::DynamoDB::Table
26+ Properties :
27+ TableName : MyTestTable
28+ AttributeDefinitions :
29+ -
30+ AttributeName : id
31+ AttributeType : S
32+ KeySchema :
33+ -
34+ AttributeName : id
35+ KeyType : HASH
36+ ProvisionedThroughput :
37+ ReadCapacityUnits : 1
38+ WriteCapacityUnits : 1
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const expect = require ( 'chai' ) . expect
4+ const fetch = require ( 'node-fetch' )
5+ const { deployWithRandomStage, removeService, getDynamodbItem } = require ( '../../../utils' )
6+
7+ describe ( 'Single dynamodb Proxy Integration Test' , ( ) => {
8+ let endpoint
9+ let stage
10+ const tableName = 'MyTestTable'
11+ const config = '__tests__/integration/dynamodb/single-integration/service/serverless.yml'
12+
13+ beforeAll ( async ( ) => {
14+ const result = await deployWithRandomStage ( config )
15+
16+ stage = result . stage
17+ endpoint = result . endpoint
18+ } )
19+
20+ afterAll ( async ( ) => {
21+ removeService ( stage , config )
22+ } )
23+
24+ it ( 'should get correct response from dynamodb proxy endpoint' , async ( ) => {
25+ const testEndpoint = `${ endpoint } /dynamodb`
26+
27+ const response = await fetch ( testEndpoint , {
28+ method : 'POST' ,
29+ headers : { 'Content-Type' : 'application/json' } ,
30+ body : JSON . stringify ( { item1 : { S : 'item1' } , item2 : { S : 'item2' } } )
31+ } )
32+ expect ( response . headers . get ( 'access-control-allow-origin' ) ) . to . deep . equal ( '*' )
33+ expect ( response . status ) . to . be . equal ( 200 )
34+ const body = await response . json ( )
35+
36+ const item = await getDynamodbItem ( tableName , body . id )
37+ expect ( item ) . to . be . deep . equal ( {
38+ Item : {
39+ id : { S : body . id } ,
40+ item1 : { S : 'item1' } ,
41+ item2 : { S : 'item2' }
42+ }
43+ } )
44+ } )
45+ } )
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ const aws = require('aws-sdk')
99const s3 = new aws . S3 ( )
1010
1111const region = 'us-east-1'
12+ const dynamodb = new aws . DynamoDB ( { region } )
1213const cloudformation = new aws . CloudFormation ( { region } )
1314
1415function getApiGatewayEndpoint ( outputs ) {
@@ -25,6 +26,19 @@ async function getStackOutputs(stackName) {
2526 return _ . zipObject ( keys , values )
2627}
2728
29+ async function getDynamodbItem ( tableName , hashKey ) {
30+ return await dynamodb
31+ . getItem ( {
32+ Key : {
33+ id : {
34+ S : hashKey
35+ }
36+ } ,
37+ TableName : tableName
38+ } )
39+ . promise ( )
40+ }
41+
2842async function getS3Object ( bucket , key ) {
2943 const resp = await s3
3044 . getObject ( {
@@ -77,5 +91,6 @@ module.exports = {
7791 removeService,
7892 deployWithRandomStage,
7993 getS3Object,
80- deleteS3Object
94+ deleteS3Object,
95+ getDynamodbItem
8196}
You can’t perform that action at this time.
0 commit comments