sqs-consumer icon indicating copy to clipboard operation
sqs-consumer copied to clipboard

Update to AWS SDK v3

Open ericyd opened this issue 3 years ago • 10 comments

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 #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)
  • [x] New feature (non-breaking change which adds functionality)
  • [x] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] My code follows the code style of this project.
  • [x] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.
  • [x] I have read the CONTRIBUTING document.
  • [ ] I have added tests to cover my changes.
  • [x] 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 avatar Feb 21 '21 20:02 ericyd

@jeanrauwers are there any plans to merge it?

artur-ma avatar Mar 10 '21 13:03 artur-ma

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

boredland avatar May 17 '21 09:05 boredland

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.

danilofuchs avatar Jun 22 '21 01:06 danilofuchs

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

FloatingGhost avatar Jul 19 '21 12:07 FloatingGhost

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

luads avatar Jul 29 '21 08:07 luads

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

flashpaper12 avatar Aug 29 '21 23:08 flashpaper12

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

ericyd avatar Sep 02 '21 18:09 ericyd

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

razor-x avatar Feb 15 '22 22:02 razor-x

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?

FloatingGhost avatar Apr 12 '22 11:04 FloatingGhost

Any alternatives beside using the fork?

jaschaio avatar Aug 14 '22 17:08 jaschaio

Any updates, can this finally be merged

justinasfour04 avatar Nov 02 '22 23:11 justinasfour04

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 avatar Dec 08 '22 20:12 nicholasgriffintn

Published as [email protected] 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 avatar Dec 11 '22 18:12 nicholasgriffintn

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[bot] avatar Mar 17 '23 18:03 github-actions[bot]