Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
aws-sdk-wrap
Advanced tools
Wrapper around aws-sdk.
When dealing with the aws-sdk a lot, some calls become very repetitive and achieving code coverage becomes tiresome. This wrapper abstracts some of the repetitive logic.
Some examples of repetitive logic are:
.promise()
Install with npm:
$ npm install --save aws-sdk-wrap
Ensure required peer dependencies are available.
import AWS from 'aws-sdk-wrap';
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
AWS({
services: {
S3: S3Client,
'S3:CMD': { PutObjectCommand }
}
})
.call('S3:PutObjectCommand', { /* ... */ })
.then(/* ... */)
.catch(/* ... */);
where the first parameter is the service, the second parameter is the method and the third parameter are the "params" passed into the call.
Services are lazily initialized on first access.
One can access an aws-sdk
service directly by calling e.g. aws.get('S3')
.
The action
is of the format path.to.service:functionName
.
Gets the service from the underlying aws-sdk
and initialize it with the available config iff the service is not initialized yet.
Then calls the function with the passed params
(which needs to contain the appropriate parameters for the function).
The available call options
are detailed below.
Get the service from the underlying aws-sdk
without initializing it. Possible to access nested paths.
Updates the global aws config of the passed aws-sdk
via AWS.config.update
.
In most cases this should not be necessary to use.
Splits messages
into groups and calls sqs.SendMessageBatch for every group.
Batch sizes can be modified by the batchSize
option. Failed calls will be retried up to the maxRetries
option.
The available sendMessageBatch options
are detailed below.
Return the Dead Letter Queue Url configured for the passed queue url
Initialize a queue processor lambda handler with steps. Steps need to be defined in the steps directory as separate STEPNAME.js
files. Each queueUrl used by a step must be defined in queueUrls.
Each step
should export:
schema<Joi>
: Joi schemahandler<function(payload, event, stepContext): steps>
: execution logic ingesting payload and eventnext
: array of next possible stepsqueueUrl
: the queue that the step is ingested intodelay = 0
(optional): the amount of seconds that the message is delayed, defaults to undefined, i.e. the queue defaultretry = null
(optional): Declare object that is then used to instantiate RetryError
internallytimeout = 900
(optional): Timeout for individual step. Should allow for extra overhead for message management / processing and account for concurrency.groupIdFunction = undefined
(optional): Generator function for the groupId. Takes step payload as parameterdeduplicationIdFunction = undefined
(optional): Generator function for the deduplicationId. Takes step payload as parameterbefore<function(stepContext, payloads[]): steps>
(optional): called before first step is executedafter<function(stepContext): steps>
(optional):The schema needs to define the event name under name
. New events that are to be re-queued into the queue need to be returned from the handler
, before
or after
function as an array.
Exposes:
ingest
: Method used to seed queue. Note that messages generated inside a step should simply be returned from that step.handler
: Lambda function handler that is triggered by sqsdigraph
: Visualize flow using viz-js.com.Please see tests for example.
RetryError
: Can be thrown from step logic or declared on step to trigger (code) retry logicPrepare message object with options. Currently options include:
delaySeconds
(integer): used to set the delay for a specific message. Supersedes the corresponding batch option.groupId
(string): group id for the message, can only be set for steps that do not define groupIdFunction
deduplicationId
(string): deduplication id for the message, can only be set for steps that do not define deduplicationIdFunction
urgent
(boolean): message is immediately enqueued if returned from before or handler, instead of at the very endAdds an object to an Amazon S3 bucket gzipped. Uses s3:putObject.
Retrieves objects from Amazon S3, expecting it to be gzipped. Uses s3:getObject.
Retrieves only the metadata from an object in an Amazon S3 bucket. Uses s3:headObject.
Delete object from an Amazon S3 bucket at key. Uses s3:deleteObject.
List objects keys in an Amazon S3 bucket. Internally this pages until the limit is reached or no more keys are available. Uses s3:listObjectsV2.
Returns a non-ASCII key representation for an encoded s3 key. Useful to obtain the
not-encoded key representation after calling listObjects
.
Options details:
onNotFound
(Function): Return value is returned from corresponding function. Return value is returned from corresponding function.onUpdate
(Function): Executed after an item is updated successfully.onCreate
(Function): Executed after an item is created successfully.
Instantiates Model.Creates entry if key does not exist. Otherwise updates the item.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses update
Creates entry if key does not exist. Otherwise replaces entire entry if item exists.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses put
Edits an existing item's attributes. Can only update an item if it exists.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.onNotFound
(Function): Overrides Model onNotFound
function.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses update
Deletes an item. Can only delete an item if it exists.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.onNotFound
(Function): Overrides Model onNotFound
function.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses delete
Returns entry or null if not found.
Options include (all optional):
toReturn
(Array): Fields to return.onNotFound
(Function): Overrides Model onNotFound
function.Internally uses get
Creates entry if key does not exist. Otherwise errors.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.onAlreadyExists
(Function): Overrides Model onAlreadyExists
function.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses put
Pages through table based on primary key values.
Options include (all optional):
index
(String): Index name.limit
(Array): Maximum number of items to retrieve. If set to null
, will exhaustively paginate.consistent
(Boolean): Enables ConsistentRead.conditions
(Object): Conditions that must be met for operation to succeed.filters
(Object): Conditions to filter the query results after execution (still executed on AWS).toReturn
(Array): Fields to return.cursor
(String): Cursor to page through query results.Internally uses query
Replaces entire entry if item exists. Otherwise errors.
Options include (all optional):
conditions
(Object|Array): Conditions that must be met for operation to succeed.onNotFound
(Function): Overrides Model onNotFound
function.expectedErrorCodes
(Array): Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.toReturn
(Array): Fields to return on item.Internally uses put
Scans through every item in a table or secondary index.
Options include (all optional):
index
(String): Index name.limit
(Array): Maximum number of items to retrieve.consistent
(Boolean): Enables ConsistentRead.filters
(Object): Conditions to filter the query results after execution (still executed on AWS).toReturn
(Array): Fields to return.lastEvaluatedKey
(Object): Primary key of first item to be evaluated by operation.Internally uses scan
Returns subset of cloudformation template.
Type: Object
Default: N/A
AWS Services that should be available for this utility.
Type: Logger
Default: null
Provide logger. E.g. logplease or lambda-rollbar.
When an unexpected error is risen, information is logged using .error(...)
.
Type: Object
Default: {}
AWS Config object used to initialize the service.
This only affects initialized services. To update the global AWS config use updateGlobalConfig
.
Type: Object
Default: {}
Declare service specific configurations. E.g. configService = { dynamodb: { ... } }
.
Type: Function
Default: () => {}
Callback function that is called everytime after the AWS service is called, containing all information about the call and response.
Type: list
Default: []
Provide string list of expected AWS error codes. Promise succeeds on expected error with error code as string.
Type: object
Default: null
Provide additional debug information for failure case.
Used to overwrite global logger. Set to null
to prevent logging of errors.
Type: integer
Default: 10
Specify the size of each batch that will be sent. Should never exceed 10.
Type: integer
Default: 10
Number of times to retry any failed requests.
Type: Function
Default: (count) => 30 * (count ** 2)
The length of time the function will wait after each failed request before retrying.
Type: integer
Default: null
Set DelaySeconds option.
FAQs
Wrapper around aws-sdk
We found that aws-sdk-wrap demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.