-
Notifications
You must be signed in to change notification settings - Fork 5
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!: upgrade AWS SDK to v3 #83
base: master
Are you sure you want to change the base?
Changes from all commits
cc41566
c59f07d
c520dc9
3030463
472d2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# Needed for DynamoDB Local, which is used for unit tests | ||
FROM openjdk:15-alpine3.11 | ||
# Java JDK is needed for DynamoDB Local, which is used for unit tests | ||
FROM amazoncorretto:18-alpine3.15 | ||
|
||
# And our own stuff goes here | ||
WORKDIR /usr/app | ||
COPY . ./ | ||
RUN apk add --update \ | ||
yarn \ | ||
python \ | ||
python-dev \ | ||
python3 \ | ||
python3-dev \ | ||
py-pip \ | ||
build-base \ | ||
nodejs \ | ||
npm | ||
npm |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,10 @@ module.exports = async () => { | |
port, | ||
clientConfig: { | ||
endpoint, | ||
sslEnabled: false, | ||
region: "local", | ||
credentials: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my testing, I got prompts to fetch new AWS SSO credentials unless I provided dummy credentials for the local DynamoDB. |
||
accessKeyId: "foo", | ||
secretAccessKey: "baz", | ||
}, | ||
}, | ||
options: ["-inMemory"], | ||
tables: [], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@ginger.io/beyonce", | ||
"version": "0.0.66", | ||
"version": "0.0.67", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR has breaking changes, but since we haven't hit version 1, I'm assuming we're ok with just continuing to bump the version like this instead of going to version 1.0.0 now. LMK if you'd prefer otherwise! |
||
"description": "Type-safe DynamoDB query builder for TypeScript. Designed with single-table architecture in mind.", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
|
@@ -12,8 +12,9 @@ | |
"./src" | ||
], | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "3.113.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm pinning to the same versions that |
||
"@aws-sdk/lib-dynamodb": "3.113.0", | ||
"@ginger.io/jay-z": "0.0.14", | ||
"aws-sdk": "^2.853.0", | ||
"aws-xray-sdk": "^3.2.0", | ||
"fast-json-stable-stringify": "^2.1.0", | ||
"js-yaml": "^3.13.1", | ||
|
@@ -22,7 +23,7 @@ | |
"yargs": "^15.3.1" | ||
}, | ||
"devDependencies": { | ||
"@shelf/jest-dynamodb": "^1.7.0", | ||
"@shelf/jest-dynamodb": "3.3.0", | ||
"@types/jest": "^25.1.4", | ||
"@types/js-yaml": "^3.12.2", | ||
"@types/libsodium-wrappers": "^0.7.8", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export {} | ||
|
||
// @aws-sdk/client-dynamodb version 3.150.0 causes the build to fail if targeting a Nodejs environment instead of dom, | ||
// since it expects several types that are available only in the browser. | ||
// See https://stackoverflow.com/a/69581652/17092655. | ||
declare global { | ||
type ReadableStream = unknown | ||
type Blob = unknown | ||
type File = unknown | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { JayZ } from "@ginger.io/jay-z" | ||
import { DynamoDB } from "aws-sdk" | ||
import { DynamoDB } from "@aws-sdk/client-dynamodb" | ||
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb" | ||
import { captureAWSClient } from "aws-xray-sdk" | ||
import { UpdateItemExpressionBuilder } from "./expressions/UpdateItemExpressionBuilder" | ||
import { groupModelsByType } from "./groupModelsByType" | ||
|
@@ -16,7 +17,7 @@ import { ParallelScanConfig, ScanBuilder } from "./ScanBuilder" | |
import { Table } from "./Table" | ||
import { ExtractKeyType, GroupedModels, TaggedModel } from "./types" | ||
import { updateItemProxy } from "./updateItemProxy" | ||
import { decryptOrPassThroughItem, encryptOrPassThroughItem, MaybeEncryptedItem } from "./util" | ||
import { decryptOrPassThroughItem, encryptOrPassThroughItem, formatDynamoDBItem, MaybeEncryptedItem } from "./util" | ||
|
||
export interface Options { | ||
jayz?: JayZ | ||
|
@@ -41,12 +42,14 @@ export interface ScanOptions { | |
* does auto mapping between JSON <=> DynamoDB Items | ||
*/ | ||
export class Beyonce { | ||
private client: DynamoDB.DocumentClient | ||
private client: DynamoDBDocumentClient | ||
private jayz?: JayZ | ||
private consistentReads: boolean | ||
|
||
constructor(private table: Table<string, string>, dynamo: DynamoDB, options: Options = {}) { | ||
this.client = new DynamoDB.DocumentClient({ service: dynamo }) | ||
this.client = DynamoDBDocumentClient.from(dynamo, { | ||
marshallOptions: { removeUndefinedValues: true } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Attempting to write keys with undefined values results in errors unless specifying this option. |
||
}) | ||
if (options.xRayTracingEnabled) { | ||
// hack per: https://github.com/aws/aws-xray-sdk-node/issues/23#issuecomment-509745488 | ||
captureAWSClient((this.client as any).service) | ||
|
@@ -139,7 +142,8 @@ export class Beyonce { | |
const items: ExtractKeyType<T>[] = [] | ||
const unprocessedKeys: T[] = [] | ||
results.forEach((result) => { | ||
items.push(...result.items) | ||
const formattedItems = result.items.map(item => item ? formatDynamoDBItem(item) : item) | ||
items.push(...formattedItems) | ||
unprocessedKeys.push(...result.unprocessedKeys) | ||
}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import { DynamoDB } from "aws-sdk" | ||
|
||
export type DynamoDBExpression = { | ||
expression: DynamoDB.DocumentClient.ConditionExpression | ||
attributeNames: DynamoDB.DocumentClient.ExpressionAttributeNameMap | ||
attributeValues: DynamoDB.DocumentClient.ExpressionAttributeValueMap | ||
expression: string | ||
attributeNames: Record<string, string> | ||
attributeValues: Record<string, string> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To get AWS SDK v3 support for the local DynamoDB, we have to upgrade
jest-dynamodb
, which necessitates upgrading to a newer version of Nodejs, which necessitates switching from the deprecated base Docker image we were using to this one.