aws-drivers
Wrappers for AWS SDK services that make life easier (sometimes).
Drivers
Constructing drivers
Each driver has a constructor of the following form:
constructor({ [client], [useClient], [level], [...other] })
- [client] - { Object } - config field that is used to construct client (ignored when pre-configured client is passed)
- [useClient] - { Object } - pre-configured client
- [level] - { String } - log level
- [...other] - { Any } - driver-specific config options
S3
getSignedUrl(context, { operation, parameters, urlTTL })
Get a pre-signed URL for a given operation name.
- operation - { String } - the name of the operation to call
- parameters - { Object } - parameters to pass to the operation
- urlTTL - { Number } - URL expiration time in seconds
putObject(context, { bucket, data, [key] })
Adds an object to a bucket.
- bucket - { String } - name of the bucket
- data - { Any } - object data; can be a String or any type that can be stringified
- [key] - { String } - object key [random UUID by default]
SQS
Additional config properties:
- [maxConcurrency] - { Number } - max number of concurrent AWS API calls [defaults to
Infinity
]
parse(context, input)
Validates and parses input, where input can be SQS message or SQS event. Sample output:
[
{
"body": {
"foo": "foo",
"bar": "bar"
},
"messageAttributes": {
"baz": 12345
},
"messageId": 1234567890
}
]
send(context, queueUrl, messages)
Sends messages to the specified queue using batch API to reduce number of calls.
- queueUrl - { String } - the URL of the SQS queue to which batched messages are sent
- messages - { Any | Any[] } - messages to be sent
sendToDLQ(context, dlqUrl, items)
Formats and sends messages to the specified deadletter queue.
- dlqUrl - { String } - the deadletter queue URL to which messages are sent
- items - { Object | Object[] } - items to send to the deadletter queue, where:
- event - { Any } - original payload that can't be processed
- error - { Object } - error that occured during processing
These message attributes are added to each message:
- err.message - error message
- err.stack - error stack trace
- context.awsRequestId - requestId for the current request, provided by Amazon
- origin.messageId - original messageId (if payload is SQS message)
License
The MIT License (MIT)
Copyright (c) 2019 Anton Bazhal
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.