-
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.
chore(examples): update api-websocket-lambda-dynamodb example (#146)
This PR makes a couple of updates to the api-websocket-lambda-dynamodb example test - Updates the Lambda runtime to `NODEJS_LATEST` - This also requires switching from `aws-sdk` (v2) to `@aws-sdk/client-*` (v3) - Updates the CDK code to use L2s instead of L1s - Adds validation to the test to ensure that the code actually works (it didn't) closes #144, re #145
- Loading branch information
Showing
14 changed files
with
445 additions
and
1,895 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,23 +1,27 @@ | ||
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT-0 | ||
|
||
const AWS = require('aws-sdk'); | ||
const { DynamoDBDocumentClient, PutCommand } = require('@aws-sdk/lib-dynamodb'); | ||
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb'); | ||
|
||
const ddb = new AWS.DynamoDB.DocumentClient({ apiVersion: '2012-08-10', region: process.env.AWS_REGION }); | ||
const client = new DynamoDBClient({}); | ||
const ddb = DynamoDBDocumentClient.from(client); | ||
|
||
exports.handler = async event => { | ||
const putParams = { | ||
console.log(`event: ${JSON.stringify(event)}`); | ||
const command = new PutCommand({ | ||
TableName: process.env.TABLE_NAME, | ||
Item: { | ||
connectionId: event.requestContext.connectionId | ||
} | ||
}; | ||
}); | ||
|
||
try { | ||
await ddb.put(putParams).promise(); | ||
await ddb.send(command) | ||
} catch (err) { | ||
return { statusCode: 500, body: 'Failed to connect: ' + JSON.stringify(err) }; | ||
} | ||
|
||
console.log("Successfully connected"); | ||
return { statusCode: 200, body: 'Connected.' }; | ||
}; |
11 changes: 0 additions & 11 deletions
11
examples/api-websocket-lambda-dynamodb/onconnect/package.json
This file was deleted.
Oops, something went wrong.
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
11 changes: 0 additions & 11 deletions
11
examples/api-websocket-lambda-dynamodb/ondisconnect/package.json
This file was deleted.
Oops, something went wrong.
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
11 changes: 0 additions & 11 deletions
11
examples/api-websocket-lambda-dynamodb/sendmessage/package.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.