Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cumulus/aws-client

Package Overview
Dependencies
Maintainers
8
Versions
135
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cumulus/aws-client

Utilities for working with AWS

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
103
decreased by-17.6%
Maintainers
8
Weekly downloads
 
Created
Source

@cumulus/aws-client

Utilities for working with AWS. These utilities can be used for interacting with live AWS services or Localstack. For ease of setup, testing, and credential management, code interacting with AWS services should use the helpers in this module.

⚠️ The documented API of this package will not change without a deprecation warning being provided in earlier releases. Code in this package that is not documented in this README may change without warning, and is not considered part of the package's public API.

Usage

npm install @cumulus/aws-client

Interacting with Localstack

To use these utilities with Localstack, make sure you have a running instance of Localstack and set this environment variable:

NODE_ENV=test

API

Modules

CloudFormation
CloudwatchEvents
DynamoDb
KMS
Kinesis
Lambda
S3
SNS
SQS
SecretsManager
StepFunctions

Classes

DynamoDbSearchQueue

Class to efficiently search all of the items in a DynamoDB table, without loading them all into memory at once. Handles paging.

S3ListObjectsV2Queue

Class to efficiently list all of the objects in an S3 bucket, without loading them all into memory at once. Handles paging of listS3ObjectsV2 requests.

CloudFormation

CloudFormation.describeCfStack(StackName) ⇒ Promise.<CloudFormation.Stack>

Describes a given CloudFormation stack

See CloudFormation.Stack

Kind: static method of CloudFormation
Returns: Promise.<CloudFormation.Stack> - The resources belonging to the stack

ParamTypeDescription
StackNamestringThe name of the CloudFormation stack to query

CloudFormation.describeCfStackResources(StackName) ⇒ Promise.<CloudFormation.StackResources>

Describes the resources belonging to a given CloudFormation stack

See CloudFormation.StackResources

Kind: static method of CloudFormation
Returns: Promise.<CloudFormation.StackResources> - The resources belonging to the stack

ParamTypeDescription
StackNamestringThe name of the CloudFormation stack to query

CloudFormation.getCfStackParameterValues(stackName, parameterKeys) ⇒ Promise.<Object>

Get parameter values for the given CloudFormation stack

Kind: static method of CloudFormation
Returns: Promise.<Object> - Object keyed by parameter names

ParamTypeDescription
stackNamestringThe name of the CloudFormation stack to query
parameterKeysArray.<string>Key names for the stack parameters that you want to return

CloudwatchEvents

CloudwatchEvents.putEvent(name, schedule, state, [description], [role]) ⇒ Promise.<CloudWatchEvents.PutRuleResponse>

Create a CloudWatch Events rule

Kind: static method of CloudwatchEvents

ParamTypeDescription
namestringthe rule name
schedulestringa ScheduleExpression
statestringthe state of the rule
[description]string
[role]stringa Role ARN

DynamoDb

DynamoDb.get ⇒ Promise.<Object>

Call DynamoDb client get

See DocumentClient.get() for descriptions of params and the return data.

Kind: static property of DynamoDb
Throws:

  • RecordDoesNotExist if a record cannot be found
ParamTypeDescription
paramsObject
params.tableNamestringTable name to read
params.itemAWS.DynamoDB.DocumentClient.KeyKey identifying object to get
params.clientAWS.DynamoDB.DocumentClientInstance of a DynamoDb DocumentClient
params.getParamsObjectAdditional parameters for DocumentClient.get()

DynamoDb.scan ⇒ Promise.<Object>

Call DynamoDb client scan

See DocumentClient.scan() for descriptions of params and the return data.

Kind: static property of DynamoDb

ParamType
paramsObject

DynamoDb.createAndWaitForDynamoDbTable(params) ⇒ Promise.<Object>

Create a DynamoDB table and then wait for the table to exist

Kind: static method of DynamoDb
Returns: Promise.<Object> - the output of the createTable call

ParamTypeDescription
paramsObjectthe same params that you would pass to AWS.createTable See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-property

DynamoDb.deleteAndWaitForDynamoDbTableNotExists(params) ⇒ Promise

Delete a DynamoDB table and then wait for the table to not exist

Kind: static method of DynamoDb

ParamTypeDescription
paramsObjectthe same params that you would pass to AWS.deleteTable See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#deleteTable-property

KMS

KMS.createKey(params) ⇒ Promise.<Object>

Create a KMS key

See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/KMS.html#createKey-property for allowed params and return value.

Kind: static method of KMS

ParamType
paramsObject

KMS.encrypt(KeyId, Plaintext) ⇒ Promise.<string>

Encrypt a string using KMS

Kind: static method of KMS
Returns: Promise.<string> - the Base 64 encoding of the encrypted value

ParamTypeDescription
KeyIdstringthe KMS key to use for encryption
Plaintextstringthe string to be encrypted

KMS.decryptBase64String(ciphertext) ⇒ string

Decrypt a KMS-encrypted string, Base 64 encoded

Kind: static method of KMS
Returns: string - the plaintext

ParamTypeDescription
ciphertextstringa KMS-encrypted value, Base 64 encoded

Kinesis

Kinesis.describeStream(params, retryOptions) ⇒ Promise.<Object>

Describe a Kinesis stream.

Kind: static method of Kinesis
Returns: Promise.<Object> - The stream description response

ParamTypeDescription
paramsObject
params.StreamNamestringA Kinesis stream name
retryOptionsObjectOptions passed to p-retry module

Lambda

Lambda.invoke(name, payload, type) ⇒ Promise.<AWS.Lambda.InvocationResponse>

Invoke a Lambda function

Kind: static method of Lambda

ParamTypeDescription
namestringLambda function name
payloadanythe payload to the Lambda function
typestringthe invocation type

S3

S3.deleteS3Object

Delete an object from S3

Kind: static property of S3

ParamTypeDescription
bucketstringbucket where the object exists
keystringkey of the object to be deleted promise of the object being deleted

S3.headObject ⇒ Promise

Get an object header from S3

Kind: static property of S3
Returns: Promise - returns response from S3.headObject as a promise

ParamTypeDescription
Bucketstringname of bucket
Keystringkey for object (filepath + filename)
retryOptionsObjectoptions to control retry behavior when an object does not exist. See https://github.com/tim-kos/node-retry#retryoperationoptions By default, retries will not be performed

S3.s3PutObject

Put an object on S3

Kind: static property of S3

ParamTypeDescription
paramsObjectsame params as https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property promise of the object being put

S3.s3CopyObject ⇒ Promise

Copy an object from one location on S3 to another

Kind: static property of S3
Returns: Promise - promise of the object being copied

ParamTypeDescription
paramsObjectsame params as https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property

S3.promiseS3Upload ⇒ Promise

Upload data to S3

Note: This is equivalent to calling aws.s3().upload(params).promise()

Kind: static property of S3
Returns: Promise - see S3.upload()

ParamTypeDescription
paramsObjectsee S3.upload()

S3.s3GetObjectTagging ⇒ Promise.<AWS.S3.GetObjectTaggingOutput>

Get object Tagging from S3

Kind: static property of S3
Returns: Promise.<AWS.S3.GetObjectTaggingOutput> - the promised response from S3.getObjectTagging

ParamTypeDescription
bucketstringname of bucket
keystringkey for object (filepath + filename)

S3.s3PutObjectTagging ⇒ Promise

Puts object Tagging in S3 https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObjectTagging-property

Kind: static property of S3
Returns: Promise - returns response from S3.getObjectTagging as a promise

ParamTypeDescription
Bucketstringname of bucket
Keystringkey for object (filepath + filename)
TaggingObjecttagging object

S3.getS3Object ⇒ Promise

Get an object from S3

Kind: static property of S3
Returns: Promise - returns response from S3.getObject as a promise

ParamTypeDescription
Bucketstringname of bucket
Keystringkey for object (filepath + filename)
retryOptionsObjectoptions to control retry behavior when an object does not exist. See https://github.com/tim-kos/node-retry#retryoperationoptions By default, retries will not be performed

S3.getS3ObjectReadStream ⇒ ReadableStream

Deprecated

Get a readable stream for an S3 object.

Kind: static property of S3
Throws:

  • Error if S3 object cannot be found
ParamTypeDescription
bucketstringthe S3 object's bucket
keystringthe S3 object's key

S3.recursivelyDeleteS3Bucket ⇒ Promise

Delete a bucket and all of its objects from S3

Kind: static property of S3
Returns: Promise - the promised result of S3.deleteBucket

ParamTypeDescription
bucketstringname of the bucket

S3.calculateS3ObjectChecksum ⇒ Promise.<(number|string)>

Deprecated

Calculate checksum for S3 Object

Kind: static property of S3
Returns: Promise.<(number|string)> - calculated checksum

ParamTypeDescription
paramsObjectparams
params.algorithmstringchecksum algorithm
params.bucketstringS3 bucket
params.keystringS3 key
[params.options]Objectcrypto.createHash options

S3.s3Join(args) ⇒ string

Join strings into an S3 key without a leading slash

Kind: static method of S3
Returns: string - the full S3 key

ParamTypeDescription
argsstring | Array.<string>the strings to join

S3.parseS3Uri(uri) ⇒ Object

parse an s3 uri to get the bucket and key

Kind: static method of S3
Returns: Object - Returns an object with Bucket and Key properties

ParamTypeDescription
uristringmust be a uri with the s3:// protocol

S3.buildS3Uri(bucket, key) ⇒ string

Given a bucket and key, return an S3 URI

Kind: static method of S3
Returns: string - an S3 URI

ParamTypeDescription
bucketstringan S3 bucket name
keystringan S3 key

S3.s3TagSetToQueryString(tagset) ⇒ string

Convert S3 TagSet Object to query string e.g. [{ Key: 'tag', Value: 'value }] to 'tag=value'

Kind: static method of S3
Returns: string - tags query string

ParamTypeDescription
tagsetArray.<Object>S3 TagSet array

S3.s3ObjectExists(params) ⇒ Promise.<boolean>

Test if an object exists in S3

Kind: static method of S3
Returns: Promise.<boolean> - a Promise that will resolve to a boolean indicating if the object exists

ParamTypeDescription
paramsObjectsame params as https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#headObject-property

S3.waitForObjectToExist(params) ⇒ Promise.<undefined>

Wait for an object to exist in S3

Kind: static method of S3

ParamTypeDefaultDescription
paramsObject
params.bucketstring
params.keystring
[params.interval]number1000interval before retries, in ms
[params.timeout]number30000timeout, in ms

S3.putFile(bucket, key, filename) ⇒ Promise

Upload a file to S3

Kind: static method of S3

ParamTypeDescription
bucketstringthe destination S3 bucket
keystringthe destination S3 key
filenamefilenamethe local file to be uploaded

S3.downloadS3File(s3Obj, filepath) ⇒ Promise.<string>

Downloads the given s3Obj to the given filename in a streaming manner

Kind: static method of S3
Returns: Promise.<string> - returns filename if successful

ParamTypeDescription
s3ObjObjectThe parameters to send to S3 getObject call
filepathstringThe filepath of the file that is downloaded

S3.getObjectSize(params) ⇒ Promise.<(number|undefined)>

Get the size of an S3 object

Kind: static method of S3
Returns: Promise.<(number|undefined)> - object size, in bytes

ParamTypeDescription
paramsObject
params.bucketstring
params.keystring
params.s3AWS.S3an S3 client instance

S3.getTextObject(bucket, key) ⇒ Promise.<string>

Fetch the contents of an S3 object

Kind: static method of S3
Returns: Promise.<string> - the contents of the S3 object

ParamTypeDescription
bucketstringthe S3 object's bucket
keystringthe S3 object's key

S3.getJsonS3Object(bucket, key) ⇒ Promise.<*>

Fetch JSON stored in an S3 object

Kind: static method of S3
Returns: Promise.<*> - the contents of the S3 object, parsed as JSON

ParamTypeDescription
bucketstringthe S3 object's bucket
keystringthe S3 object's key

S3.getObjectReadStream(params) ⇒ Readable

Get a readable stream for an S3 object

Kind: static method of S3

ParamTypeDescription
paramsObject
params.s3AWS.S3an AWS.S3 instance
params.bucketstringthe bucket of the requested object
params.keystringthe key of the requested object

S3.getS3ObjectReadStreamAsync(bucket, key) ⇒ ReadableStream

Get a readable stream for an S3 object.

Use getS3Object() before fetching stream to deal with eventual consistency issues by checking for object with retries.

Kind: static method of S3
Throws:

  • Error if S3 object cannot be found
ParamTypeDescription
bucketstringthe S3 object's bucket
keystringthe S3 object's key

S3.fileExists(bucket, key) ⇒ Promise

Check if a file exists in an S3 object

Kind: static method of S3
Returns: Promise - returns the response from S3.headObject as a promise

ParamTypeDescription
bucketstringname of the S3 bucket
keystringkey of the file in the S3 bucket

S3.deleteS3Files(s3Objs) ⇒ Promise

Delete files from S3

Kind: static method of S3
Returns: Promise - A promise that resolves to an Array of the data returned from the deletion operations

ParamTypeDescription
s3ObjsArrayAn array of objects containing keys 'Bucket' and 'Key'

S3.uploadS3FileStream(fileStream, bucket, key, s3opts) ⇒ Promise

Upload the file associated with the given stream to an S3 bucket

Kind: static method of S3
Returns: Promise - A promise

ParamTypeDescription
fileStreamReadableStreamThe stream for the file's contents
bucketstringThe S3 bucket to which the file is to be uploaded
keystringThe key to the file in the bucket
s3optsObjectOptions to pass to the AWS sdk call (defaults to {})

S3.listS3Objects(bucket, prefix, skipFolders) ⇒ Promise

List the objects in an S3 bucket

Kind: static method of S3
Returns: Promise - A promise that resolves to the list of objects. Each S3 object is represented as a JS object with the following attributes: Key, ETag, LastModified, Owner, Size, StorageClass.

ParamTypeDescription
bucketstringThe name of the bucket
prefixstringOnly objects with keys starting with this prefix will be included (useful for searching folders in buckets, e.g., '/PDR')
skipFoldersbooleanIf true don't return objects that are folders (defaults to true)

S3.listS3ObjectsV2(params) ⇒ Promise.<Array>

Fetch complete list of S3 objects

listObjectsV2 is limited to 1,000 results per call. This function continues listing objects until there are no more to be fetched.

The passed params must be compatible with the listObjectsV2 call.

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#listObjectsV2-property

Kind: static method of S3
Returns: Promise.<Array> - resolves to an array of objects corresponding to the Contents property of the listObjectsV2 response

ParamTypeDescription
paramsObjectparams for the s3.listObjectsV2 call

S3.calculateObjectHash(params)

Calculate the cryptographic hash of an S3 object

Kind: static method of S3

ParamTypeDescription
paramsObject
params.s3AWS.S3an AWS.S3 instance
params.algorithmstringcksum, or an algorithm listed in openssl list -digest-algorithms
params.bucketstring
params.keystring

S3.validateS3ObjectChecksum(params) ⇒ Promise.<boolean>

Validate S3 object checksum against expected sum

Kind: static method of S3
Returns: Promise.<boolean> - returns true for success
Throws:

  • InvalidChecksum - Throws error if validation fails
ParamTypeDescription
paramsObjectparams
params.algorithmstringchecksum algorithm
params.bucketstringS3 bucket
params.keystringS3 key
params.expectedSumnumber | stringexpected checksum
[params.options]Objectcrypto.createHash options

S3.getFileBucketAndKey(pathParams) ⇒ Array.<string>

Extract the S3 bucket and key from the URL path parameters

Kind: static method of S3
Returns: Array.<string> - [Bucket, Key]

ParamTypeDescription
pathParamsstringpath parameters from the URL bucket/key in the form of

S3.createBucket(Bucket) ⇒ Promise

Create an S3 bucket

Kind: static method of S3

ParamTypeDescription
Bucketstringthe name of the S3 bucket to create

S3.multipartCopyObject(params) ⇒ Promise.<{etag: string}>

Copy an S3 object to another location in S3 using a multipart copy

Kind: static method of S3
Returns: Promise.<{etag: string}> - object containing the ETag of the destination object

ParamTypeDefaultDescription
paramsObject
params.sourceBucketstring
params.sourceKeystring
params.destinationBucketstring
params.destinationKeystring
[params.ACL]stringan S3 Canned ACL
[params.copyTags]booleanfalse

S3.moveObject(params) ⇒ Promise.<undefined>

Move an S3 object to another location in S3

Kind: static method of S3

ParamTypeDefaultDescription
paramsObject
params.sourceBucketstring
params.sourceKeystring
params.destinationBucketstring
params.destinationKeystring
[params.ACL]stringan S3 Canned ACL
[params.copyTags]booleanfalse

SNS

SNS.publishSnsMessage(snsTopicArn, message, retryOptions) ⇒ Promise.<undefined>

Publish a message to an SNS topic. Does not catch errors, to allow more specific handling by the caller.

Kind: static method of SNS

ParamTypeDescription
snsTopicArnstringSNS topic ARN
messageObjectMessage object
retryOptionsObjectoptions to control retry behavior when publishing a message fails. See https://github.com/tim-kos/node-retry#retryoperationoptions

SQS

SQS.deleteSQSMessage ⇒ Promise

Delete a given SQS message from a given queue.

Kind: static property of SQS
Returns: Promise - an AWS SQS response

ParamTypeDescription
queueUrlstringurl of the SQS queue
receiptHandleintegerthe unique identifier of the sQS message

SQS.createQueue(QueueName) ⇒ Promise.<string>

Create an SQS Queue. Properly handles localstack queue URLs

Kind: static method of SQS
Returns: Promise.<string> - the Queue URL

ParamTypeDescription
QueueNamestringqueue name

SQS.sendSQSMessage(queueUrl, message) ⇒ Promise

Send a message to AWS SQS

Kind: static method of SQS
Returns: Promise - resolves when the messsage has been sent

ParamTypeDescription
queueUrlstringurl of the SQS queue
messagestring | Objecteither string or object message. If an object it will be serialized into a JSON string.

SQS.receiveSQSMessages(queueUrl, options) ⇒ Promise.<Array>

Receives SQS messages from a given queue. The number of messages received can be set and the timeout is also adjustable.

Kind: static method of SQS
Returns: Promise.<Array> - an array of messages

ParamTypeDefaultDescription
queueUrlstringurl of the SQS queue
optionsObjectoptions object
[options.numOfMessages]integer1number of messages to read from the queue
[options.visibilityTimeout]integer30number of seconds a message is invisible after read
[options.waitTimeSeconds]integer0number of seconds to poll SQS queue (long polling)

SQS.sqsQueueExists(queue) ⇒ Promise.<boolean>

Test if an SQS queue exists

Kind: static method of SQS
Returns: Promise.<boolean> - a Promise that will resolve to a boolean indicating if the queue exists

ParamTypeDescription
queueObjectqueue name or url

SecretsManager

StepFunctions

StepFunctions.describeExecution(params) ⇒ Promise.<Object>

Call StepFunctions DescribeExecution

See StepFunctions.describeExecution() for descriptions of params and the return data.

If a ThrottlingException is received, this function will retry using an exponential backoff.

Kind: static method of StepFunctions

ParamType
paramsObject

StepFunctions.describeStateMachine(params) ⇒ Promise.<Object>

Call StepFunctions DescribeStateMachine

See StepFunctions.describeStateMachine() for descriptions of params and the return data.

If a ThrottlingException is received, this function will retry using an exponential backoff.

Kind: static method of StepFunctions

ParamType
paramsObject

StepFunctions.executionExists(executionArn) ⇒ Promise.<boolean>

Check if a Step Function Execution exists

If a ThrottlingException is received, this function will retry using an exponential backoff.

Kind: static method of StepFunctions

ParamTypeDescription
executionArnstringthe ARN of the Step Function Execution to check for

StepFunctions.getExecutionHistory(params) ⇒ Promise.<Object>

Call StepFunctions GetExecutionHistory

See StepFunctions.getExecutionHistory() for descriptions of params and the return data.

If a ThrottlingException is received, this function will retry using an exponential backoff.

Kind: static method of StepFunctions

ParamType
paramsObject

StepFunctions.listExecutions(params) ⇒ Promise.<Object>

Call StepFunctions ListExecutions

See StepFunctions.listExecutions() for descriptions of params and the return data.

If a ThrottlingException is received, this function will retry using an exponential backoff.

Kind: static method of StepFunctions

ParamType
paramsObject

DynamoDbSearchQueue

Class to efficiently search all of the items in a DynamoDB table, without loading them all into memory at once. Handles paging.

Kind: global class

dynamoDbSearchQueue.peek() ⇒ Promise.<Object>

View the next item in the queue

This does not remove the object from the queue. When there are no more items in the queue, returns 'null'.

Kind: instance method of DynamoDbSearchQueue
Returns: Promise.<Object> - an item from the DynamoDB table

dynamoDbSearchQueue.shift() ⇒ Promise.<Object>

Remove the next item from the queue

When there are no more items in the queue, returns 'null'.

Kind: instance method of DynamoDbSearchQueue
Returns: Promise.<Object> - an item from the DynamoDB table

S3ListObjectsV2Queue

Class to efficiently list all of the objects in an S3 bucket, without loading them all into memory at once. Handles paging of listS3ObjectsV2 requests.

Kind: global class

s3ListObjectsV2Queue.peek() ⇒ Promise.<Object>

View the next item in the queue

This does not remove the object from the queue. When there are no more items in the queue, returns 'null'.

Kind: instance method of S3ListObjectsV2Queue
Returns: Promise.<Object> - an S3 object description

s3ListObjectsV2Queue.shift() ⇒ Promise.<Object>

Remove the next item from the queue

When there are no more items in the queue, returns 'null'.

Kind: instance method of S3ListObjectsV2Queue
Returns: Promise.<Object> - an S3 object description

About Cumulus

Cumulus is a cloud-based data ingest, archive, distribution and management prototype for NASA's future Earth science data streams.

Cumulus Documentation

Contributing

To make a contribution, please see our contributing guidelines.


Generated automatically using npm run build-docs

Keywords

FAQs

Package last updated on 28 Jul 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc