-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move to use of AWS SDK v3 and Correct history
* Update to use aws-sdk v3 clients and commands * Updated @aws-sdk/* to the latest version * Update Readme.md, removed some comments from test * Updated receiveMessage() and fixed sqsMessageSizeUtils.test.js * Added simple examples of lambda functions * Updated Readme.md Feature/switch to aws sdk v3 (#12) Feature/switch to aws sdk v3 fix (#13) * Removed integration-test folder * Updated jest paths for test matcher Update remote refs
- Loading branch information
1 parent
ba7d3eb
commit f2f634d
Showing
10 changed files
with
12,490 additions
and
1,117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
coverage | ||
node_modules | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Example of lambda function which receives messages from sqs with big content. | ||
*/ | ||
const middy = require('@middy/core'); | ||
const SqsExtendedClient = require('sqs-extended-client'); | ||
|
||
const sqsClientConfig = { region: 'eu-west-2'}; | ||
const s3ClientConfig = { region: 'eu-west-2'}; | ||
|
||
const sqsExtendedClient = new SqsExtendedClient({ | ||
sqsClientConfig, | ||
s3ClientConfig, | ||
bucketName: '--BUCKET-NAME--' | ||
}); | ||
|
||
const processRecord = async (data) => { | ||
// Do whatever is required with every record from sqs. | ||
} | ||
|
||
const processEvent = async (event) => { | ||
await Promise.all( | ||
event.Records.map(async (record) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
konrad-dvla
Author
Contributor
|
||
return processRecord(record); | ||
}) | ||
); | ||
}; | ||
|
||
const handler = middy(processEvent); | ||
|
||
// Ensure that middleware is called | ||
handler.use(sqsExtendedClient.middleware()); | ||
|
||
module.exports = { handler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Example of lambda function which send message with big content to SQS. | ||
*/ | ||
const SqsExtendedClient = require('sqs-extended-client'); | ||
|
||
const DEFAULT_MESSAGE_SIZE_THRESHOLD = 262144; | ||
const QUEUE_URL = '--YOUR-QUEUE-URL--' | ||
|
||
const sqsClientConfig = { region: 'eu-west-2'}; | ||
const s3ClientConfig = { region: 'eu-west-2'}; | ||
|
||
const sqsExtendedClient = new SqsExtendedClient({ | ||
sqsClientConfig, | ||
s3ClientConfig, | ||
bucketName: '--BUCKET-NAME--', | ||
messageSizeThreshold: DEFAULT_MESSAGE_SIZE_THRESHOLD | ||
}); | ||
|
||
const handler = async (event, context ) => { | ||
|
||
const content = '--BIG-CONTENT--'; | ||
|
||
const sqsResponse = await sqsExtendedClient.sendMessage({ | ||
QueueUrl: QUEUE_URL, | ||
MessageBody: JSON.stringify(content), | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
body: { | ||
MessageId: sqsResponse.MessageId, | ||
} | ||
} | ||
} | ||
|
||
module.exports = { handler } |
Oops, something went wrong.
change to
.forEach
.based from what I experience It does not really wait an async function when using
.map