Skip to content

Update to AWS SDK v3 - #252

Merged
nicholasgriffintn merged 19 commits into
bbc:mainfrom
ericyd:aws-sdk-v3
Dec 16, 2022
Merged

Update to AWS SDK v3#252
nicholasgriffintn merged 19 commits into
bbc:mainfrom
ericyd:aws-sdk-v3

Conversation

@ericyd

@ericyd ericyd commented Feb 21, 2021

Copy link
Copy Markdown
Contributor

Description

  1. Update the peer and development dependencies to AWS SDK v3.
  2. Update all SQS client method calls to use updated syntax
  3. Update error types to match new error type thrown by client
  4. Update tests to run with the new API calls and error structure

Motivation and Context

  1. This change updates the library to use the newest major version of the AWS SDK, which modularizes the entire SDK and substantially changes the API. As AWS pushed developers towards the new SDK, it will be important for widely-used libraries to update functionality
  2. Closes Plans to support aws-sdk v3? #251
  3. Mainly, this was selfishly motivated. I thought we needed this update for a project I'm working on. Then we pivoted and decided we didn't need it, but not before I had done nearly all the work to update the lib. I decided to finish my work and share the results in case they are useful to others. It's a small enough lib that if others needed this functionality locally, they could reasonably just copy/paste the changes into their project.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Notes on the Checklist:

  1. I didn't really add tests because technically the behavior shouldn't change with this PR. However, I did substantial updates to the tests to make them work. The test coverage should not have changed at all, but I can add tests if desired.
  2. I know the contributing guidelines recommend waiting for issue acknowledgement before working on a PR. However, as indicated above, I thought I needed this work done for a project and by the time I realized I didn't need it, it was already nearly done. Please note: if you don't want to use these changes, I am 100% OK with that. I am just posting them here for the community if others find themselves wanting/needing these changes, or if the library maintainers want to use this as a starting place.

Testing

In addition to updating the unit tests, I tested basic functionality locally using this script. I

// To test this against live resources, you must provision and AWS SQS queu first.
// These commands assume you have the AWS CLI installed and configured
//
// Create a queue
//    queue=$(aws sqs create-queue --queue-name my-queue --query "QueueUrl")
// Send a message to the queue
//    aws sqs send-message --queue-url $queue --message-body '{"user_id": "123123123"}'
// Run the consumer app locally
//    npx ts-node test-consumer.ts
// Delete queue when testing is complete
//    aws sqs delete-queue --queue-url $queue

import { Consumer, Message } from './index'
import { SQSClient } from '@aws-sdk/client-sqs'

const ACCOUND_ID = '123456789'
const QUEUE_NAME = 'my-queue'
const REGION = 'us-west-2'
const queueUrl = `https://sqs.${REGION}.amazonaws.com/${ACCOUND_ID}/${QUEUE_NAME}`

const sqs = new SQSClient({ region: REGION, credentialDefaultProvider: () => () => Promise.resolve({ accessKeyId: 'accessKeyId', secretAccessKey: 'secretAccessKey', sessionToken: 'sessionToken' }) })

export const handleMessage = async (message: Message) => {
  try {
    const parsed = JSON.parse(message.Body)
    console.log(parsed)
  } catch (e) {
    console.error('Parse failure!', e)
  }
}

const app = Consumer.create({
  queueUrl,
  handleMessage,
  sqs,
})

app.on('error', (err) => {
  console.error(err.message)
})

app.on('processing_error', (err) => {
  console.error(err.message)
})

app.on('timeout_error', (err) => {
  console.error(err.message)
})

app.start()

@ericyd
ericyd requested a review from a team as a code owner February 21, 2021 20:55
(only required for types)
@artur-ma

Copy link
Copy Markdown

@jeanrauwers are there any plans to merge it?

Comment thread src/consumer.ts
@boredland

Copy link
Copy Markdown

I know its not nice to bump things, but what is the status of this PR?

@danilofuchs

Copy link
Copy Markdown

I have the bad feeling BBC has dropped support for this project or there are no maintainers available.
It hasn't received an update in 7 months, ignoring crucial security fixes and very nice improvements such as this.

@FloatingGhost

Copy link
Copy Markdown

I have the bad feeling BBC has dropped support for this project or there are no maintainers available.

we still use it internally, so i would believe it to be the latter case here

i'll poke the code owners to see if i can get anything going here, since we need v3 support too

@luads

luads commented Jul 29, 2021

Copy link
Copy Markdown

Thanks for this PR! I'll be running some tests with our consumers.

@flashpaper12

Copy link
Copy Markdown

Bump for merge on this please as aws sdk v2 is now going to become legacy

@ericyd

ericyd commented Sep 2, 2021

Copy link
Copy Markdown
Contributor Author

To everyone who feels inclined to bump this or the corresponding issue #251 : there are a total of 4 files and a total of 460 lines of code in this entire repository. I know npm install is super convenient but honestly just copy/paste the files from this PR into your project, or fork and publish it to npm under a slightly different name. Maintaining open source projects is hard, time consuming, and thankless. You can throw the maintainers a bone and solve your problem at the same time

@razor-x

razor-x commented Feb 15, 2022

Copy link
Copy Markdown

Hopefully this makes it in here, but if anyone would like to use this, I've forked and published the code from this PR to npm: https://www.npmjs.com/package/@rxfork/sqs-consumer

@FloatingGhost

Copy link
Copy Markdown

there is hope yet

apparently amazon themselves contacted the people that own it and as far as i can tell basically offered to help. maybe this issue will finally leave purgatory!

fun times, eh?

@jaschaio

Copy link
Copy Markdown

Any alternatives beside using the fork?

@justin-is-a-builder

Copy link
Copy Markdown

Any updates, can this finally be merged

@nicholasgriffintn

nicholasgriffintn commented Dec 8, 2022

Copy link
Copy Markdown
Member

Thank you all for bearing with us, I'm looking into this now (at least soon), I don't know if it will be done as part of this PR or as part of a new one though as this PR does have conflicts.

@nicholasgriffintn
nicholasgriffintn requested a review from a team as a code owner December 9, 2022 16:59

@nicholasgriffintn nicholasgriffintn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Few bits to note from my journey with this PR so far:

  • I do need to go through these changes to make sure that SQS Consumer is still doing the same thing as it did before as they are quite significant
  • SdkError from the smithy-client has been deprecated so will need to be replaced
  • Updated the tests and merged in the latest code

This is just an initial pass through, we are working on this, but it may be a little bit longer :)

Comment thread src/index.ts Outdated
Comment thread README.md Outdated
@nicholasgriffintn

Copy link
Copy Markdown
Member

Published as sqs-consumer@6.0.0-alpha.1 for further testing, in case anyone wants to use it early.

Will be using this version to ensure that everything still works as we would expect, can't guarantee it does until this has been released as a full version though.

@nicholasgriffintn
nicholasgriffintn merged commit ac988cf into bbc:main Dec 16, 2022
@github-actions

Copy link
Copy Markdown

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plans to support aws-sdk v3?