Skip to content

Commit

Permalink
feat: upgrade the aws-sdk to support the sqs json protocol (#440)
Browse files Browse the repository at this point in the history
* chore: upgrade @aws-sdk/client-sqs to version which supports sqs json protocol

* fix: integration tests

* fix: remove v2 deprecated localstack envs

Localstack V2 deprecated the HOST_TMP_FOLDER and DATA_DIR envs. The DATA_DIR env was replaced with a PERSISTENCE env, but that is a paid feature of localstack now.

* fix: healthcheck for localstack verifies if sqs service is running

The localstack healthcheck endpoint now gives back a JSON object with a status for each service. This change makes it so that the healthcheck passes if the SQS service is in 'running' state.

* chore: fixing localstack version

* chore: updating types

* chore: updating test types

* chore: upgrading sqs-producer

* chore: update lock

Destroyed previously created lock and re ran to ensure it's BBC generated.

---------

Co-authored-by: Nicholas Griffin <[email protected]>
  • Loading branch information
1 parent cce922d commit 32f6f1e
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 448 deletions.
905 changes: 474 additions & 431 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
"p-event": "^4.2.0",
"prettier": "^3.0.3",
"sinon": "^17.0.0",
"sqs-producer": "^3.4.0",
"sqs-producer": "^4.0.0",
"ts-node": "^10.9.1",
"typedoc": "^0.25.2",
"typescript": "^5.2.2"
},
"dependencies": {
"@aws-sdk/client-sqs": "^3.428.0",
"@aws-sdk/client-sqs": "^3.447.0",
"debug": "^4.3.4"
},
"peerDependencies": {
"@aws-sdk/client-sqs": "^3.428.0"
"@aws-sdk/client-sqs": "^3.447.0"
},
"mocha": {
"spec": "test/tests/**/**/*.test.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
DeleteMessageBatchCommandInput,
ReceiveMessageCommand,
ReceiveMessageCommandInput,
ReceiveMessageCommandOutput
ReceiveMessageCommandOutput,
QueueAttributeName
} from '@aws-sdk/client-sqs';

import { ConsumerOptions, StopOptions, UpdatableOptions } from './types';
Expand Down Expand Up @@ -43,7 +44,7 @@ export class Consumer extends TypedEventEmitter {
private postReceiveMessageCallback?: () => Promise<void>;
private sqs: SQSClient;
private handleMessageTimeout: number;
private attributeNames: string[];
private attributeNames: QueueAttributeName[];
private messageAttributeNames: string[];
private shouldDeleteMessages: boolean;
private batchSize: number;
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SQSClient, Message } from '@aws-sdk/client-sqs';
import { SQSClient, Message, QueueAttributeName } from '@aws-sdk/client-sqs';

export interface ConsumerOptions {
/**
Expand All @@ -10,7 +10,7 @@ export interface ConsumerOptions {
* `['All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount']`).
* @defaultvalue `[]`
*/
attributeNames?: string[];
attributeNames?: QueueAttributeName[];
/**
* List of message attributes to retrieve (i.e. `['name', 'address']`).
* @defaultvalue `[]`
Expand Down
10 changes: 3 additions & 7 deletions test/scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ version: '3'
services:
localstack:
container_name: local_sqs_aws
image: localstack/localstack:1.2.0@sha256:41216e34e25546654c58b8075b133027eab3d958e605ef2e7af168d1f05a9364
command: sh -c "/usr/local/bin/init.sh && exec myexecutable"
image: localstack/localstack:3.0.1@sha256:de413eee81c94bfd9b2206c016b82e83a3b2b8abd5775d05dbf829be2b02afb4
environment:
- AWS_DEFAULT_REGION=eu-west-1
- EDGE_PORT=4566
- SERVICES=sqs
- AWS_ACCESS_KEY_ID=key
- AWS_SECRET_ACCESS_KEY=secret
- DATA_DIR=/tmp/localstack/data
- HOST_TMP_FOLDER=${TMPDIR:-/tmp/}localstack
- DOCKER_HOST=unix:///var/run/docker.sock
- DEBUG=1
ports:
- "4566-4599:4566-4599"
volumes:
- '${TMPDIR:-/tmp/localstack}:/tmp/localstack'
- '/var/run/docker.sock:/var/run/docker.sock'
- ./localstack:/docker-entrypoint-initaws.d
- ./localstack:/etc/localstack/init/ready.d
healthcheck:
test: curl http://localhost:4566/health || exit 1
test: curl http://localhost:4566/_localstack/health | jq '.services.sqs' | grep -q -x 'running'
interval: 20s
retries: 5
start_period: 20s
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/initIntTests.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
docker-compose --file ./test/scripts/docker-compose.yml up -d
docker compose --file ./test/scripts/docker-compose.yml up -d

if [ $? -eq 0 ]
then
Expand Down
Empty file modified test/scripts/localstack/init.sh
100644 → 100755
Empty file.
9 changes: 7 additions & 2 deletions test/tests/consumer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
DeleteMessageBatchCommand,
DeleteMessageCommand,
ReceiveMessageCommand,
SQSClient
SQSClient,
QueueAttributeName
} from '@aws-sdk/client-sqs';
import { assert } from 'chai';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -701,9 +702,13 @@ describe('Consumer', () => {
Messages: [messageWithAttr]
});

const attributeNames: QueueAttributeName[] = [
'ApproximateReceiveCount' as QueueAttributeName
];

consumer = new Consumer({
queueUrl: QUEUE_URL,
attributeNames: ['ApproximateReceiveCount'],
attributeNames,
region: REGION,
handleMessage,
sqs
Expand Down

0 comments on commit 32f6f1e

Please sign in to comment.