@alpha-lambda/aws-drivers
v3.2.0
Published
Wrappers for AWS SDK services that make life easier (sometimes)
Downloads
169
Readme
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
DynamoDBDocumentClient
Additional config properties:
- [attempts] - { Number } - max number of attempts to
batchGet
items
batchGet(context, params)
Returns the attributes of one or more items from one or more tables (parameters reference). Automatically retries when API call returns UnprocessedKeys
delete(context, params)
Deletes a single item in a table by primary key (parameters reference).
get(context, params)
Returns a set of attributes for the item with the given key (parameters reference).
put(context, params)
Creates a new item, or replaces an old item (parameters reference).
query(context, params)
Finds items based on key values (parameters reference).
queryAll(context, params, [callback])
The same as query
but keeps calling DynamoDB until all items are returned (parameters reference). If callback is provided, it's called each time DynamoDB returns items.
scan(context, params)
Returns one or more items and item attributes by accessing every item in a table or a secondary index (parameters reference).
scanAll(context, params, { [concurrency], [callback] })
The same as scan
but keeps calling DynamoDB until all items are returned (parameters reference). If callback is provided, it's called each time DynamoDB returns items. To perform parallel scan, set concurrency
to a value greater than 1
.
update(context, params)
Edits an existing item's attributes, or adds a new item to the table if it does not already exist (parameters reference).
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, body, [key] }, params)
Adds an object to a bucket.
- bucket - { String } - name of the bucket
- body - { Buffer | Typed Array | Blob | String | ReadableStream } - object data
- [key] - { String } - object key [random UUID by default]
- [params] - { Object } - any additional input parameters that S3.putObject allows
upload(context, { bucket, body, [key], [options] }, params)
Uploads an arbitrarily sized buffer, blob, or stream, using intelligent concurrent handling of parts if the payload is large enough. - bucket - { String } - name of the bucket - body - { Buffer | Typed Array | Blob | String | ReadableStream } - object data - [key] - { String } - object key [random UUID by default] - [options] - { Object } - upload operation options such as part and/or queue size - [params] - { Object } - any additional input parameters that S3.upload allows
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 - { Object | Object[] } - messages to be sent, where each message has the following properties:
- body - { Any } - the body of the message
- [delaySeconds] - { Number } - the length of time, in seconds, for which a specific message is delayed
- [messageAttributes] - { Object } - key-value pairs of attributes to be added to the message
- [dedupId] - { String } - required for and only used in FIFO queues: (docs)
- [groupId] - { String } - required for and only used in FIFO queues: (docs)
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-2023 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.