Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
feat: replace all aws-sdk v2 usages with aws sdk v3 clients
Browse files Browse the repository at this point in the history
  • Loading branch information
gsingh1 committed Jul 1, 2022
1 parent 237e0dc commit c0fa19a
Show file tree
Hide file tree
Showing 15 changed files with 4,078 additions and 3,361 deletions.
7,295 changes: 4,000 additions & 3,295 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@
"@middy/http-json-body-parser": "^3.0.4",
"@middy/input-output-logger": "^3.0.4",
"@middy/ssm": "^3.0.4",
"aws-sdk": "^2.1153.0",
"aws-signed-axios": "^1.1.0",
"aws-xray-sdk-core": "^3.3.6",
"lodash": "^4.17.21",
Expand Down
2 changes: 2 additions & 0 deletions packages/checklist-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"url": "https://github.com/fourTheorem/slic-starter"
},
"devDependencies": {
"@aws-sdk/client-dynamodb": "^3.118.1",
"@aws-sdk/lib-dynamodb": "^3.118.1",
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"aws-sdk-client-mock": "^1.0.0",
Expand Down
17 changes: 10 additions & 7 deletions packages/checklist-service/scripts/dynamodb/populate-shares.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient({
endpoint: process.env.DYNAMODB_ENDPOINT_URL
})
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
const {
DynamoDBDocumentClient,
PutCommand
} = require('@aws-sdk/lib-dynamodb')

const dynamoClient = new DynamoDBClient({ endpoint: process.env.DYNAMODB_ENDPOINT_URL })
const docClient = DynamoDBDocumentClient.from(dynamoClient)

/*
[email protected] UserId: mock-auth-dGVzdGFjY291bnQxQGV4YW1wbGUuY29t
Expand Down Expand Up @@ -40,11 +44,10 @@ async function run () {
await Promise.all(
records.map(record =>
docClient
.put({
.send(new PutCommand({
TableName: 'checklists',
Item: record
})
.promise()
}))
)
)
console.log('Finished querying records')
Expand Down
29 changes: 16 additions & 13 deletions packages/checklist-service/scripts/dynamodb/query-shares.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const AWS = require('aws-sdk')
const docClient = new AWS.DynamoDB.DocumentClient({
endpoint: process.env.DYNAMODB_ENDPOINT_URL
})
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
const {
BatchGetCommand,
DynamoDBDocumentClient,
QueryCommand
} = require('@aws-sdk/lib-dynamodb')

const tableName = 'checklists'
const dynamoClient = new DynamoDBClient({ endpoint: process.env.DYNAMODB_ENDPOINT_URL })
const docClient = DynamoDBDocumentClient.from(dynamoClient)

const TableName = 'checklists'

/*
[email protected] UserId: mock-auth-dGVzdGFjY291bnQxQGV4YW1wbGUuY29t
Expand All @@ -13,8 +18,8 @@ async function run () {
console.log('Querying records')
const userId = 'mock-auth-dGVzdGFjY291bnQyQGV4YW1wbGUuY29t' // testaccount2
const lists = (await docClient
.query({
TableName: tableName,
.send(new QueryCommand({
TableName,
ProjectionExpression:
'listId, #nm, #description, createdAt, sharedListOwner, userId',
KeyConditionExpression: 'userId = :userId',
Expand All @@ -25,8 +30,7 @@ async function run () {
ExpressionAttributeValues: {
':userId': userId
}
})
.promise()).Items
}))).Items

console.log({ lists })
const sharedListKeys = lists
Expand All @@ -36,9 +40,9 @@ async function run () {
// Next, find the actual records for shared lists with name, description and createdAt values
if (sharedListKeys.length) {
const sharedLists = (await docClient
.batchGet({
.send(new BatchGetCommand({
RequestItems: {
[tableName]: {
[TableName]: {
Keys: sharedListKeys,
ProjectionExpression:
'listId, #nm, #description, createdAt, userId',
Expand All @@ -48,8 +52,7 @@ async function run () {
}
}
}
})
.promise()).Responses[tableName]
}))).Responses[TableName]
// Merge values from actual records into shared list records
console.log('sharedlists***', { sharedLists })
sharedLists.forEach(sharedList => {
Expand Down
22 changes: 12 additions & 10 deletions packages/checklist-service/scripts/dynamodb/update-query.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const AWS = require('aws-sdk')
const { DynamoDBClient } = require('@aws-sdk/client-dynamodb')
const {
DynamoDBDocumentClient,
UpdateCommand
} = require('@aws-sdk/lib-dynamodb')

AWS.config.update({ region: process.env.AWS_REGION })
const dynamoClient = new DynamoDBClient({ region: process.env.AWS_REGION })
const docClient = DynamoDBDocumentClient.from(dynamoClient)

const dynamoDb = new AWS.DynamoDB.DocumentClient()

const tableName = 'checklists'
const TableName = 'checklists'

const userId = 'TODO1'
const listId = 'TODO1'
Expand All @@ -15,17 +18,16 @@ async function test () {

console.log('Executing update')

const result = await dynamoDb
.update({
TableName: tableName,
const result = await docClient
.send(new UpdateCommand({
TableName,
Key: { userId, listId },
UpdateExpression: 'SET entries= :entries, updatedAt = :updatedAt',
ExpressionAttributeValues: {
':entries': entries,
':updatedAt': updatedAt
}
})
.promise()
}))

console.log('DONE', result)
}
Expand Down
12 changes: 7 additions & 5 deletions packages/e2e-tests/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const {
GetParameterCommand,
SSMClient
} = require('@aws-sdk/client-ssm')

const localConfig = require('./local-email-config.js')
const realConfig = require('test-common/real-email-config')
const AWS = require('aws-sdk')
const ssm = new AWS.SSM()

const ssmClient = new SSMClient({})
const stage = process.env.SLIC_STAGE

const frontendUrlPromise =
stage === 'local'
? Promise.resolve('http://localhost:3000')
: ssm
.getParameter({ Name: `/${stage}/frontend/url` })
.promise()
: ssmClient.send(new GetParameterCommand({ Name: `/${stage}/frontend/url` }))
.then(data => data.Parameter.Value)

export function getBaseUrl () {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"test-common": "*"
},
"devDependencies": {
"aws-sdk": "^2.1153.0",
"@aws-sdk/client-ssm": "^3.118.1",
"chance": "^1.1.8",
"eslint-plugin-testcafe": "^0.2.1",
"nid": "^2.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@aws-amplify/api": "^4.0.42",
"@aws-amplify/auth": "^4.5.6",
"@aws-amplify/core": "^4.5.6",
"@aws-sdk/client-cloudformation": "^3.118.1",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"awscred": "^1.5.0",
Expand Down
16 changes: 7 additions & 9 deletions packages/frontend/scripts/fetch-deployment-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const {
CloudFormationClient,
DescribeStacksCommand
} = require('@aws-sdk/client-cloudformation');
const fs = require('fs')
const path = require('path')

const awscred = require('awscred')
const { CloudFormation } = require('aws-sdk')
const yaml = require('js-yaml')

const appConfig = yaml.load(fs.readFileSync(path.resolve(__dirname, '..', '..', '..', 'app.yml'), 'utf8'))
Expand Down Expand Up @@ -37,7 +39,7 @@ if (!awsRegion) {

console.log('Using region', awsRegion)

const cf = new CloudFormation({ region: awsRegion })
const cf = new CloudFormationClient({ region: awsRegion })

const envFilename = '.env.production'
fs.writeFileSync(
Expand All @@ -61,9 +63,7 @@ Promise.all([getUserServiceEnv(), getApiEndpointsEnv()])

function getUserServiceEnv () {
console.log(userServiceStackName)
return cf
.describeStacks({ StackName: userServiceStackName })
.promise()
return cf.send(new DescribeStacksCommand({ StackName: userServiceStackName }))
.then((data) => {
if (data.Stacks && data.Stacks[0]) {
const stageEnvContents = data.Stacks[0].Outputs.filter(
Expand Down Expand Up @@ -96,9 +96,7 @@ function getApiEndpointsEnv () {
? Promise.resolve(
`https://api.${domainSuffix}${nsDomain}${apiStackPaths[stackNamePrefix]}`
)
: cf
.describeStacks({ StackName: `${stackNamePrefix}-${stage}` })
.promise()
: cf.send(new DescribeStacksCommand({ StackName: `${stackNamePrefix}-${stage}` }))
.then(
(data) =>
data.Stacks[0].Outputs.find(
Expand Down
15 changes: 8 additions & 7 deletions packages/integration-tests/lib/backend-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const {
CloudFormationClient,
DescribeStacksCommand
} = require('@aws-sdk/client-cloudformation')
const awscred = require('awscred')
const { CloudFormation } = require('aws-sdk')

const stage = process.env.SLIC_STAGE || 'local'
const domainSuffix = stage === 'prod' ? '' : `${stage}.`
Expand All @@ -18,7 +21,7 @@ if (!awsRegion) {
'The region must be set using any of the AWS-SDK-supported methods to the region of the deployed backend'
)
}
const cf = new CloudFormation({ region: awsRegion })
const cf = new CloudFormationClient({ region: awsRegion })

let backendConfig

Expand All @@ -42,11 +45,10 @@ async function loadBackendConfig () {
}
}

const apiEndpoints = await getApiEndpoints(cf)
const apiEndpoints = await getApiEndpoints()

backendConfig = await cf
.describeStacks({ StackName: stackName })
.promise()
.send(new DescribeStacksCommand({ StackName: stackName }))
.then(data => {
if (data.Stacks && data.Stacks[0]) {
const exportBackendPairs = data.Stacks[0].Outputs.filter(
Expand Down Expand Up @@ -81,8 +83,7 @@ function getApiEndpoints () {
`https://api.${domainSuffix}${nsDomain}${apiStackPaths[apiName]}`
)
: cf
.describeStacks({ StackName: `${apiName}-${stage}` })
.promise()
.send(new DescribeStacksCommand({ StackName: `${apiName}-${stage}` }))
.then(
data =>
data.Stacks[0].Outputs.find(
Expand Down
22 changes: 12 additions & 10 deletions packages/integration-tests/lib/cognito-util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const {
AdminCreateUserCommand,
AdminDeleteUserCommand,
AdminInitiateAuthCommand,
AdminRespondToAuthChallengeCommand,
CognitoIdentityProviderClient
} = require('@aws-sdk/client-cognito-identity-provider')
const awscred = require('awscred')
const AWS = require('aws-sdk')
const jwt = require('jsonwebtoken')
const chance = require('chance').Chance()

Expand All @@ -9,7 +15,7 @@ const { loadBackendConfig } = require('./backend-config')
const generatePassword = () => `${chance.string({ length: 10 })}!Aa0`

const awsRegion = awscred.loadRegionSync()
const cognitoServiceProvider = new AWS.CognitoIdentityServiceProvider({ region: awsRegion })
const cognitoServiceProvider = new CognitoIdentityProviderClient({ region: awsRegion })

async function createUser () {
const email = generateEmailAddress()
Expand All @@ -25,7 +31,7 @@ async function createUser () {
UserAttributes: [{ Name: 'email', Value: email }]
}

await cognitoServiceProvider.adminCreateUser(createRequest).promise()
await cognitoServiceProvider.send(new AdminCreateUserCommand(createRequest))

const authRequest = {
AuthFlow: 'ADMIN_NO_SRP_AUTH',
Expand All @@ -37,9 +43,7 @@ async function createUser () {
}
}

const authResponse = await cognitoServiceProvider
.adminInitiateAuth(authRequest)
.promise()
const authResponse = await cognitoServiceProvider.send(new AdminInitiateAuthCommand(authRequest))

const challengeRequest = {
UserPoolId: backendConfig.userPoolId,
Expand All @@ -52,9 +56,7 @@ async function createUser () {
}
}

const challengeResponse = await cognitoServiceProvider
.adminRespondToAuthChallenge(challengeRequest)
.promise()
const challengeResponse = await cognitoServiceProvider.send(new AdminRespondToAuthChallengeCommand(challengeRequest))

const { 'cognito:username': userId } = jwt.decode(
challengeResponse.AuthenticationResult.IdToken
Expand All @@ -76,7 +78,7 @@ async function deleteUser (user) {
UserPoolId: backendConfig.userPoolId,
Username: user.email
}
await cognitoServiceProvider.adminDeleteUser(deleteRequest).promise()
await cognitoServiceProvider.send(new AdminDeleteUserCommand(deleteRequest))
}

module.exports = {
Expand Down
3 changes: 2 additions & 1 deletion packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
},
"keywords": [],
"devDependencies": {
"@aws-sdk/client-cloudformation": "^3.118.1",
"@aws-sdk/client-cognito-identity-provider": "^3.118.1",
"@faker-js/faker": "^7.2.0",
"aws-sdk": "^2.1153.0",
"awscred": "^1.5.0",
"axios": "^0.27.2",
"chance": "^1.1.8",
Expand Down
1 change: 0 additions & 1 deletion packages/user-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"@aws-sdk/client-cognito-identity-provider": "^3.118.0",
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"aws-sdk": "^2.1153.0",
"aws-sdk-client-mock": "^1.0.0",
"awscred": "^1.5.0",
"mock-amplify-auth": "^2.2.0",
Expand Down
1 change: 0 additions & 1 deletion packages/welcome-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"devDependencies": {
"@babel/core": "^7.18.5",
"@babel/preset-env": "^7.18.2",
"aws-sdk": "^2.1153.0",
"b": "^2.0.1",
"serverless-bundle": "^5.3.0",
"serverless-iam-roles-per-function": "^3.2.0",
Expand Down

0 comments on commit c0fa19a

Please sign in to comment.