Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-sdk-s3-persistence-adapter, aws-sdk-dynamodb-persistence-adapter): upgrade dynamodb and s3 persistence adapters to use AWS SDK v3 #699

Draft
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(aws-sdk-s3-persistence-adapter, aws-sdk-dynamodb-persistence-ada…
…pter): upgrade dynamodb and s3 persistence adapters to use AWS SDK v3
  • Loading branch information
Sam Goodwin committed Oct 27, 2021
commit 84c32e66314f585f8d63382a75710ce6767c8a39
2 changes: 1 addition & 1 deletion ask-sdk-core/package.json
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@types/sinon": "^7.0.13",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ import {
PersistenceAdapter
} from 'ask-sdk-core';
import { RequestEnvelope } from 'ask-sdk-model';
import { DynamoDB } from 'aws-sdk';
import { DeleteCommand, DeleteCommandInput, DynamoDBDocumentClient, GetCommand, GetCommandInput, GetCommandOutput, PutCommand, PutCommandInput } from '@aws-sdk/lib-dynamodb';
import { CreateTableInput, DynamoDB } from '@aws-sdk/client-dynamodb';
import {
PartitionKeyGenerator,
PartitionKeyGenerators
@@ -32,7 +33,7 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
protected createTable: boolean;
protected dynamoDBClient: DynamoDB;
protected partitionKeyGenerator: PartitionKeyGenerator;
protected dynamoDBDocumentClient: DynamoDB.DocumentClient;
protected dynamoDBDocumentClient: DynamoDBDocumentClient;

constructor(config: {
tableName: string,
@@ -48,13 +49,15 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
this.createTable = config.createTable === true;
this.dynamoDBClient = config.dynamoDBClient ? config.dynamoDBClient : new DynamoDB({apiVersion : 'latest'});
this.partitionKeyGenerator = config.partitionKeyGenerator ? config.partitionKeyGenerator : PartitionKeyGenerators.userId;
this.dynamoDBDocumentClient = new DynamoDB.DocumentClient({
convertEmptyValues : true,
service : this.dynamoDBClient,

this.dynamoDBDocumentClient = DynamoDBDocumentClient.from(this.dynamoDBClient, {
marshallOptions: {
convertEmptyValues : true,
},
});
// Create table when createTable is set to true and table does not exist
if (this.createTable) {
const createTableParams: DynamoDB.CreateTableInput = {
const createTableParams: CreateTableInput = {
AttributeDefinitions: [{
AttributeName: this.partitionKeyName,
AttributeType: 'S',
@@ -89,17 +92,17 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
public async getAttributes(requestEnvelope: RequestEnvelope): Promise<{[key: string]: any}> {
const attributesId = this.partitionKeyGenerator(requestEnvelope);

const getParams: DynamoDB.DocumentClient.GetItemInput = {
const getParams: GetCommandInput = {
Key : {
[this.partitionKeyName] : attributesId,
},
TableName : this.tableName,
ConsistentRead : true,
};

let data: DynamoDB.DocumentClient.GetItemOutput;
let data: GetCommandOutput;
try {
data = await this.dynamoDBDocumentClient.get(getParams).promise();
data = await this.dynamoDBDocumentClient.send(new GetCommand(getParams));
} catch (err) {
throw createAskSdkError(
this.constructor.name,
@@ -123,7 +126,7 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
public async saveAttributes(requestEnvelope: RequestEnvelope, attributes: {[key: string]: any}): Promise<void> {
const attributesId = this.partitionKeyGenerator(requestEnvelope);

const putParams: DynamoDB.DocumentClient.PutItemInput = {
const putParams: PutCommandInput = {
Item: {
[this.partitionKeyName] : attributesId,
[this.attributesName] : attributes,
@@ -132,7 +135,7 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
};

try {
await this.dynamoDBDocumentClient.put(putParams).promise();
await this.dynamoDBDocumentClient.send(new PutCommand(putParams));
} catch (err) {
throw createAskSdkError(
this.constructor.name,
@@ -149,15 +152,15 @@ export class DynamoDbPersistenceAdapter implements PersistenceAdapter {
public async deleteAttributes(requestEnvelope: RequestEnvelope): Promise<void> {
const attributesId = this.partitionKeyGenerator(requestEnvelope);

const deleteParams: DynamoDB.DocumentClient.DeleteItemInput = {
const deleteParams: DeleteCommandInput = {
Key : {
[this.partitionKeyName] : attributesId,
},
TableName : this.tableName,
};

try {
await this.dynamoDBDocumentClient.delete(deleteParams).promise();
await this.dynamoDBDocumentClient.send(new DeleteCommand(deleteParams));
} catch (err) {
throw createAskSdkError(
this.constructor.name,
7 changes: 4 additions & 3 deletions ask-sdk-dynamodb-persistence-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-dynamodb-persistence-adapter",
"version": "2.11.0",
"version": "3.0.0",
"description": "DynamoDB based implementation package of PersistenceAdapter interface in ASK SDK v2 for Node.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -29,15 +29,16 @@
"SDK"
],
"dependencies": {
"aws-sdk": "^2.163.0"
"@aws-sdk/client-dynamodb": "^3.38.0",
"@aws-sdk/lib-dynamodb": "^3.38.0"
},
"peerDependencies": {
"ask-sdk-core": "^2.0.0"
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"ask-sdk-core": "^2.11.0",
8 changes: 7 additions & 1 deletion ask-sdk-dynamodb-persistence-adapter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -8,9 +8,15 @@
"sourceMap" : true,
"alwaysStrict" : true,
"declaration" : true,
"lib": []
"lib": [
// required for compiling @aws-sdk/*
"dom"
]
},
"include": [
"lib"
],
"exclude": [
"node_modules"
]
}
2 changes: 1 addition & 1 deletion ask-sdk-express-adapter/package.json
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
"@types/chai": "^4.1.2",
"@types/express": "^4.16.1",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@types/node-forge": "^0.8.0",
"@types/semver": "^7.3.4",
"@types/sinon": "^7.0.13",
2 changes: 1 addition & 1 deletion ask-sdk-runtime/package.json
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@types/sinon": "^7.0.13",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import {
PersistenceAdapter
} from 'ask-sdk-core';
import { RequestEnvelope } from 'ask-sdk-model';
import { S3 } from 'aws-sdk';
import { DeleteObjectCommand, DeleteObjectCommandInput, GetObjectCommand, GetObjectCommandInput, GetObjectCommandOutput, PutObjectCommand, PutObjectCommandInput, S3 } from '@aws-sdk/client-s3';
import * as path from 'path';
import {
ObjectKeyGenerator,
@@ -52,15 +52,15 @@ export class S3PersistenceAdapter implements PersistenceAdapter {
public async getAttributes(requestEnvelope: RequestEnvelope): Promise<{[key: string]: string}> {
const objectId = path.join(this.pathPrefix, this.objectKeyGenerator(requestEnvelope));

const getParams: S3.GetObjectRequest = {
const getParams: GetObjectCommandInput = {
Bucket : this.bucketName,
Key : objectId,
};

let data: S3.GetObjectOutput;
let data: GetObjectCommandOutput;

try {
data = await this.s3Client.getObject(getParams).promise();
data = await this.s3Client.send(new GetObjectCommand(getParams));
} catch (err) {
if (err.code === 'NoSuchKey') {
return {};
@@ -94,14 +94,14 @@ export class S3PersistenceAdapter implements PersistenceAdapter {
public async saveAttributes(requestEnvelope: RequestEnvelope, attributes: {[key: string]: string}): Promise<void> {
const objectId = path.join(this.pathPrefix, this.objectKeyGenerator(requestEnvelope));

const putParams: S3.PutObjectRequest = {
const putParams: PutObjectCommandInput = {
Bucket : this.bucketName,
Key : objectId,
Body : JSON.stringify(attributes),
};

try {
await this.s3Client.putObject(putParams).promise();
await this.s3Client.send(new PutObjectCommand(putParams));
} catch (err) {
throw createAskSdkError(
this.constructor.name,
@@ -113,13 +113,13 @@ export class S3PersistenceAdapter implements PersistenceAdapter {
public async deleteAttributes(requestEnvelope: RequestEnvelope): Promise<void> {
const objectId = path.join(this.pathPrefix, this.objectKeyGenerator(requestEnvelope));

const deleteParams: S3.DeleteObjectRequest = {
const deleteParams: DeleteObjectCommandInput = {
Bucket : this.bucketName,
Key : objectId,
};

try {
await this.s3Client.deleteObject(deleteParams).promise();
await this.s3Client.send(new DeleteObjectCommand(deleteParams));
} catch (err) {
throw createAskSdkError(
this.constructor.name,
6 changes: 3 additions & 3 deletions ask-sdk-s3-persistence-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ask-sdk-s3-persistence-adapter",
"version": "2.11.0",
"version": "3.0.0",
"description": "S3 based implementation package of PersistenceAdapter interface in ASK SDK v2 for Node.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
@@ -25,15 +25,15 @@
"SDK"
],
"dependencies": {
"aws-sdk": "^2.163.0"
"@aws-sdk/client-s3": "^3.38.0"
},
"peerDependencies": {
"ask-sdk-core": "^2.0.0"
},
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"ask-sdk-core": "^2.11.0",
5 changes: 3 additions & 2 deletions ask-sdk-s3-persistence-adapter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -8,9 +8,10 @@
"sourceMap" : true,
"alwaysStrict" : true,
"declaration" : true,
"lib": []
"lib": ["dom"]
},
"include": [
"lib"
]
],
"exclude": ["node_modules"]
}
2 changes: 1 addition & 1 deletion ask-sdk-v1adapter/package.json
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@types/sinon": "^7.0.13",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
2 changes: 1 addition & 1 deletion ask-sdk/package.json
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
"devDependencies": {
"@types/chai": "^4.1.2",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"chai": "^4.1.2",
2 changes: 1 addition & 1 deletion ask-smapi-sdk/package.json
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
"@types/chai": "^4.1.2",
"@types/jsonpath": "^0.2.0",
"@types/mocha": "^5.0.0",
"@types/node": "^9.6.1",
"@types/node": "^12.0.0",
"@types/sinon": "^4.3.0",
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"private": true,
"scripts": {
"postinstall": "lerna bootstrap",
"lerna": "./node_modules/.bin/lerna",
"setup": "lerna exec npm install",
"bootstrap": "lerna bootstrap --force-local --hoist --nohoist=ts-node",