Skip to content

Update AWS SDK to v3 #48

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
dist
coverage
node_modules
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"extends": ["@jupiterone/eslint-config/node"],
"extends": ["@jupiterone/eslint-config/node18"],
"ignorePatterns": [
"node_modules/",
"dist/",
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:
steps:
- id: setup-node
name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Check out code repository source code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install dependencies
run: yarn
Expand Down Expand Up @@ -72,4 +72,4 @@ jobs:
echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" > .npmrc
yarn
yarn build
npm publish ./dist
npm publish ./dist
63 changes: 31 additions & 32 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
branches: ['main']

jobs:
analyze:
name: Analyze
Expand All @@ -30,41 +30,40 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
language: ['javascript']
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
136 changes: 68 additions & 68 deletions .github/workflows/peril.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: "Peril"
name: 'Peril'

on:
pull_request:

env:
env:
TRANSPONDER_DOCKER_IMAGE: 081157560428.dkr.ecr.us-east-1.amazonaws.com/transponder:1
SECURITY_SCAN_IMAGE: ghcr.io/jupiterone/security-scan:latest

Expand All @@ -17,74 +17,74 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: 14.x

- name: Run build
run: yarn install

- name: Get Variables
id: get-vars
run: |
if [[ "${GITHUB_REF}" == 'ref/head/main' && "${GITHUB_EVENT_NAME}" == 'push' ]];
then
echo ::set-output name=aws-oidc-role::arn:aws:iam::081157560428:role/github-main-role
else
echo ::set-output name=aws-oidc-role::arn:aws:iam::081157560428:role/github-pull-request-role
fi

- name: Configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ steps.get-vars.outputs.aws-oidc-role }}
role-session-name: pr-role-session
aws-region: us-east-1
- name: Checkout
uses: actions/checkout@v3

- name: ECR login
uses: aws-actions/amazon-ecr-login@v1
id: amazon-ecr-login
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18.x

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_TOKEN }}
- name: Run build
run: yarn install

- name: Pull security-scan
run: |
docker pull $SECURITY_SCAN_IMAGE

- name: Run security-scan
run: |
docker run \
--user root \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:`pwd` \
-e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
-e GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
-e GITHUB_REF_NAME=$GITHUB_REF_NAME \
-e GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
-e GITHUB_SERVER_URL=$GITHUB_SERVER_URL \
-e GITHUB_RUN_ID=$GITHUB_RUN_ID \
-e MODE=ci \
-w `pwd` $SECURITY_SCAN_IMAGE
- name: Get Variables
id: get-vars
run: |
if [[ "${GITHUB_REF}" == 'ref/head/main' && "${GITHUB_EVENT_NAME}" == 'push' ]];
then
echo ::set-output name=aws-oidc-role::arn:aws:iam::081157560428:role/github-main-role
else
echo ::set-output name=aws-oidc-role::arn:aws:iam::081157560428:role/github-pull-request-role
fi

- name: Pull transponder
run: |
docker pull $TRANSPONDER_DOCKER_IMAGE
- name: Configure aws credentials
uses: aws-actions/configure-aws-credentials@v1
with:
role-to-assume: ${{ steps.get-vars.outputs.aws-oidc-role }}
role-session-name: pr-role-session
aws-region: us-east-1

- name: Run transponder
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
-e J1_API_KEY=${{ secrets.J1_API_KEY_TRANSPONDER }} \
-e J1_API_DOMAIN=${{ secrets.J1_API_DOMAIN_TRANSPONDER }} \
-e J1_ACCOUNT_ID=${{ secrets.J1_ACCOUNT_ID_TRANSPONDER }} \
$TRANSPONDER_DOCKER_IMAGE
- name: ECR login
uses: aws-actions/amazon-ecr-login@v1
id: amazon-ecr-login

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_TOKEN }}

- name: Pull security-scan
run: |
docker pull $SECURITY_SCAN_IMAGE

- name: Run security-scan
run: |
docker run \
--user root \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:`pwd` \
-e AWS_ACCESS_KEY_ID=${{ env.AWS_ACCESS_KEY_ID }} \
-e AWS_SECRET_ACCESS_KEY=${{ env.AWS_SECRET_ACCESS_KEY }} \
-e AWS_SESSION_TOKEN=${{ env.AWS_SESSION_TOKEN }} \
-e GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
-e GITHUB_REF_NAME=$GITHUB_REF_NAME \
-e GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
-e GITHUB_SERVER_URL=$GITHUB_SERVER_URL \
-e GITHUB_RUN_ID=$GITHUB_RUN_ID \
-e MODE=ci \
-w `pwd` $SECURITY_SCAN_IMAGE

- name: Pull transponder
run: |
docker pull $TRANSPONDER_DOCKER_IMAGE

- name: Run transponder
run: |
docker run --rm -v `pwd`:`pwd` -w `pwd` \
-e J1_API_KEY=${{ secrets.J1_API_KEY_TRANSPONDER }} \
-e J1_API_DOMAIN=${{ secrets.J1_API_DOMAIN_TRANSPONDER }} \
-e J1_ACCOUNT_ID=${{ secrets.J1_ACCOUNT_ID_TRANSPONDER }} \
$TRANSPONDER_DOCKER_IMAGE
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
coverage
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ and this project adheres to

## [Unreleased]

## 2.0.0 - 2023-09-23

### Changed

- **_Breaking_** now uses the `v3` of the `aws-sdk`. Peer dependency on
`aws-sdk` dropped. Now requires `@aws-sdk/client-dynamodb` and
`@aws-sdk/lib-dynamodb`.

## 1.7.2- 2021-01-31

### Added
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ methods arguments and return values are strictly typed.
**Constructor:**

```javascript
import AWS from 'aws-sdk';
import DynamoDbDao from '@jupiterone/dynamodb-dao';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';

const dynamodb = new AWS.DynamoDB({
const ddb = new DynamoDBClient({
apiVersion: '2012-08-10'
});
})

const documentClient = new AWS.DynamoDB.DocumentClient({
service: dynamodb
const documentClient = DynamoDBDocumentClient.from(ddb, {
marshallOptions: {
removeUndefinedValues: true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this recreates the behavior of v2. Of all the things in this PR this is the one I'm most concerned about as far as breaking behavior. However, it seems removeUndefinedValues: true recreates what was the default behavior in v2:
aws/aws-sdk-js-v3#1816

}
});

// The type declaration of for the documents that we are storing
Expand Down Expand Up @@ -120,7 +122,7 @@ const { total } = await myDocumentDao.incr(
// The `number` property to increment
'total',
// The number to increment by. Defaults to 1.
5,
5
);

// `total` will have the value `-5`
Expand All @@ -133,7 +135,7 @@ const { total } = await myDocumentDao.decr(
// The `number` property to increment
'total',
// The number to decrement by. Defaults to 1.
5,
5
);
```

Expand All @@ -147,9 +149,9 @@ const { extra, total } = await myDocumentDao.multiIncr(
accountId: 'def',
},
{
'total': 5,
'extra': -1,
},
total: 5,
extra: -1,
}
);
```

Expand Down
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">= 18.0.0"
},
"scripts": {
"start:containers": "docker-compose up dynamodb",
"stop:containers": "docker-compose down",
Expand All @@ -24,23 +27,25 @@
"autobuild": "yarn build && (cd ./dist && yarn install --production && (yarn unlink || true) && yarn link) && yarn nodemon --exec 'yarn compile' --watch src -e ts --delay 3"
},
"dependencies": {
"@lifeomic/attempt": "^3.0.0",
"@lifeomic/attempt": "^3.0.3",
"lodash.chunk": "^4.2.0",
"p-map": "4.0.0"
},
"peerDependencies": {
"aws-sdk": "^2"
"@aws-sdk/client-dynamodb": "^3",
"@aws-sdk/lib-dynamodb": "^3"
},
"devDependencies": {
"@jupiterone/eslint-config": "^1.0.2",
"@jupiterone/typescript-tools": "^13.2.2",
"@aws-sdk/client-dynamodb": "^3.418.0",
"@aws-sdk/lib-dynamodb": "^3.418.0",
"@jupiterone/eslint-config": "^2.1.0",
"@jupiterone/typescript-tools": "^18",
"@types/jest": "^29",
"@types/lodash.chunk": "^4.2.6",
"@types/lodash.partition": "^4.6.6",
"@types/node": "^13.11.1",
"@types/uuid": "^8.0.0",
"aws-sdk": "^2.419.0",
"@types/node": "^18",
"aws-sdk-client-mock": "^3.0.0",
"lodash.partition": "^4.6.0",
"nodemon": "^2.0.7",
"uuid": "^8.1.0"
"nodemon": "^2.0.7"
}
}
Loading