module:aws
- Description:
AWS API interface, uses API directly for each service, JSON is returned as is but XML repsonses are converted using
fast-xml-parserinto objects.Supports local AWS SDK credentials files and sessions
When AWS environment is detected the
app.env.typeis set to aws.
- Source:
Example
# aws login
# bin/bksh -aws-sdk-profile default
> aws.s3Query("", "/", (err, rc) => {
console.log(rc?.ListAllMyBucketsResult?.Buckets)
})
Methods
(static) batchGetSecrets(optionsopt)
- Description:
Return a list of secrets
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Properties
|
(static) configureJob()
- Description:
Process AWS alarms and state notifications, if such a job is pulled from SQS queue it is handled here and never get to the jobs. SNS alarms or EventBridge events must use a SQS qeue as the target.
- Source:
(static) cwGetMetricData()
- Description:
Return collected metric statistics
Options:
- start_time - starting timestamp
- end_time - ending timestamp
- period - aggregation period in seconds, default is 60, if < 0 then dunamically set it for the time range
- age - number of ms to go back in case start_time is not specified, fraction can be used, default is 30 secs if no timestamp are given
- namespace - namespace for all metrics, default is AWS/EC2
- desc - return data in descending order
- metrics - a list with metrics to retrieve: { name: "..", stat: "..", dimensions: { key: val, ...}, [namespace: ".."], [label: "..""], [hidden: 1], [expression: ".."] }
Returns an object: { data: [{ id, label, timestamps: [], data: [] }], errors: [] }
Example:
aws.cwGetMetricData({ age: 300000, metrics: [{ name: "NetworkOut", label: "Traffic", stat: "Average", dimensions: { InstanceId: "i-1234567" } } ] }, lib.log)
- Source:
(static) cwListMetrics()
- Description:
Return metrics for the given query, the options can be specified:
- name - a metric name
- namespace - limit by namespace: AWS/AutoScaling, AWS Billing, AWS/CloudFront, AWS/DynamoDB, AWS/ElastiCache, AWS/EBS, AWS/EC2, AWS/ELB, AWS/ElasticMapReduce, AWS/Kinesis, AWS/OpsWorks, AWS/Redshift, AWS/RDS, AWS/Route53, AWS/SNS, AWS/SQS, AWS/SWF, AWS/StorageGateway
- Source:
(static) cwPutLogEvents()
- Description:
Store events in the Cloudwatch Logs. Options:
- name - log group name, required
- stream - log stream name, required
- events - a list of strings, or objects { timestamp, message }, required
- tm_pos - position in the message where the timestamp starts, default is 0
- tm_sep - separator after the timestamp, default is space
- Source:
(static) cwPutMetricAlarm()
- Description:
Creates or updates an alarm and associates it with the specified Amazon CloudWatch metric. The options specify the following:
- name - alarm name, if not specified metric name and dimensions will be used to generate alarm name
- metric - metric name, default is
CPUUtilization - namespace - AWS namespace, default is
AWS/EC2 - op - comparison operator, one of => | <= | > | < | GreaterThanOrEqualToThreshold | GreaterThanThreshold | LessThanThreshold | LessThanOrEqualToThreshold. Default is
>=. - statistic - one of SampleCount | Average | Sum | Minimum | Maximum, default is
Average - period - collection period in seconds, default is
60 - evaluationPeriods - the number of periods over which data is compared to the specified threshold, default is
15 - threshold - the value against which the specified statistic is compared, default is
90 - ok - ARN(s) to be notified on OK state
- alarm - ARN(s) to be notified on ALARM state
- insufficient_data - ARN(s) to be notified on INSUFFICIENT_DATA state
- dimensions - the dimensions for the alarm's associated metric.
- Source:
(static) cwPutMetricData()
- Description:
Publishes metric data points to Amazon CloudWatch. The argumernts specify the following:
- namespace - custome namespace, cannot start with
AWS - data - an object with metric data: { metricName: value }, ... { metricName: { value: Number, dimension1: name1, .. }, }, ... { metricName: { value: [min, max, sum, sample], dimension1: ... }, }, ...
The options can specify the following:
- storageResolution - 1 to use 1 second resolution
- timestamp - ms to be used as the timestamp instead of the current time
- namespace - custome namespace, cannot start with
- Source:
(static) cwlFilterLogEvents()
- Description:
Lists log events from the specified log group. You can list all the log events or filter the results using a filter pattern, a time range, and the name of the log stream. Options:
- name - a group name, required
- count - how many events to retrieve in one batch, 10000
- limit - total number of events to return
- filter - filter pattern
- stime - start time in ms
- etime - end time in ms
- prefix - log stream prefix pattern
- names - list of log streams to filter
- token - a previous token to start with
- timeout - how long to keep reading or waiting, ms
- Source:
(static) ddbBatchGetItem()
- Description:
Retrieve all items for given list of keys
- items is an object with table name as property name and list of options for GetItem request
- options may contain any valid native property if it starts with capital letter.
- Source:
Example
{ users: { keys: [{ id: 1, name: "john" },{ id: .., name: .. }], select: ['name','id'], consistent: true }, ... }
(static) ddbBatchWriteItem()
- Description:
Update items from the list at the same time
- items is a list of objects with table name as property and list of operations, an operation can be PutRequest or DeleteRequest
- options may contain any valid native property if it starts with capital letter.
- Source:
Example
{ table: [ { put: { id: 1, name: "tt" } }, { del: { id: 2 } }] }
(static) ddbCreateTable()
- Description:
Create a table
- attrs can be an array in native DDB JSON format or an object with name:type properties, type is one of S, N, NN, NS, BS
- options may contain any valid native property if it starts with capital letter and the following:
- waitTimeout - number of milliseconds to wait for ACTIVE status
- waitDelay - how often to pool for table status, default is 250ms
- keys is an array of column ids used for the primary key or a string with the hash key. if omitted, the first attribute will be used for the primary key
- local - an object with each property for a local secondary index name defining key format the same way as for primary keys, all Uppercase properties are added to the top index object
- global - an object for global secondary indexes, same format as for local indexes
- projections - an object with index name and list of projected properties to be included in the index or "ALL" for all properties, if omitted then default KEYS_ONLY is assumed
- readCapacity - read capacity units for provisioned throughput
- writeCapacity - write capacity units
- onDemand - billing mode, auto provision capacity and pay per request, if no read/write capacity is configured on-demand is the default
- stream - enable stream support
- Source:
Example
ddbCreateTable('users', { id: 'S', mtime: 'N', name: 'S'},
{ keys: ["id", "name"],
local: { mtime: { mtime: "HASH" } },
global: { name: { name: 'HASH', ProvisionedThroughput: { ReadCapacityUnits: 50 } } },
projections: { mtime: ['gender','age'],
name: ['name','gender'] },
stream: "NEW_IMAGE",
readCapacity: 10,
writeCapacity: 10 });
(static) ddbDeleteItem()
- Description:
Delete an item from a table
- keys is an object with name: value for hash/range attributes
- options may contain any valid native property if it starts with capital letter and the following special options:
- expr - condition expression
- values - an object with values map to be used for in the update and/or condition expressions, to be used for ExpressionAttributeValues parameters
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- returning - values to be returned on success, any value means ALL_OLD
- Source:
Example
ddbDeleteItem("users", { id: 1, name: "john" }, {})
(static) ddbDeleteTable()
- Description:
Remove a table from the database. By default the callback will ba callled only after the table is deleted, specifying
options.nowaitwill return immediately
- Source:
(static) ddbDescribeTable()
- Description:
Return table definition and parameters in the result structure with property of the given table name
- Source:
Example
{ name: { AttributeDefinitions: [], KeySchema: [] ...} }
(static) ddbDescribeTimeToLive()
- Description:
Returns status of Time to live attribute for a table
- Source:
(static) ddbGetItem()
- Description:
Retrieve one item by primary key
- keys - an object with primary key attributes name and value.
- select - list of columns to return, otherwise all columns will be returned
- options may contain any native property allowed in the request or special properties:
- consistent - set consistency level for the request
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- Source:
Example
ddbGetItem("users", { id: 1, name: "john" }, { select: 'id,name' })
(static) ddbListTables()
- Description:
Return list of tables in .TableNames property of the result
- Source:
(static) ddbPutItem()
- Description:
Put or add an item
- item is an object, type will be inferred from the native js type.
- options may contain any valid native property if it starts with capital letter or special properties:
- query - an object with column names to be used in ConditionExpression clause and value as null to set condition to { Exists: false } or any other exact value to be checked against which corresponds to { Exists: true, Value: value }
- expr - condition expression
- values - an object with values map to be used for in the update and/or condition expressions, to be used for ExpressionAttributeValues parameters
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- returning - values to be returned on success, any value means ALL_OLD
- Source:
Example
ddbPutItem("users", { id: 1, name: "john", mtime: 11233434 }, { query: { name: null } })
(static) ddbQueryTable()
- Description:
Query on a table, return all matching items
- condition is an object with name: value pairs, by default EQ opeartor is used for comparison
- options may contain any valid native property if it starts with capital letter or special property:
- start - defines starting primary key when paginating, can be a string/number for hash or an object with hash/range properties
- consistent - set consistency level for the request
- select - list of attributes to get only
- total - return number of matching records
- count - limit number of record in result
- desc - descending order
- sort - index name to use, indexes are named the same as the corresponding column, with index primary keys for Keycondition will be used
- ops - an object with operators to be used for properties if other than EQ.
- keys - list of primary key columns, if there are other properties in the condition then they will be put into QueryFilter instead of KeyConditions. If keys are absent, all properties in the condition are treated as primary keys.
- projection - projection expression
- values - an object with values map to be used for in the update and/or condition expressions, to be used for ExpressionAttributeValues parameters
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- expr - filtering expression
- Source:
Example
aws.ddbQueryTable("users", { id: 1, name: "john" }, { select: 'id,name', ops: { name: 'gt' } })
aws.ddbQueryTable("users", { id: 1, name: "john", status: "ok" }, { keys: ["id"], select: 'id,name', ops: { name: 'gt' } })
aws.ddbQueryTable("users", { id: 1 }, { expr: "status=:s", values: { s: "status" } })
(static) ddbScanTable()
- Description:
Scan a table for all matching items
- condition is an object with name: value pairs or a string with FilterExpression
- options may contain any valid native property if it starts with capital letter or special property:
- start - defines starting primary key
- ops - an object with operators to be used for properties if other than EQ.
- projection - projection expression
- values - an object with values map to be used for in the update and/or condition expressions, to be used for ExpressionAttributeValues parameters
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- Source:
Example
aws.ddbScanTable("users", { id: 1, name: 'a' }, { ops: { name: 'gt' }})
aws.ddbScanTable("users", "id=:id AND name=:name", { values: { id: 1, name: 'a' } });
(static) ddbTransactWriteItems()
- Description:
Update items from the list at the same time in one transaction, on any failure everything is rolled back
- items is a list of operations to be performed in the same format as for aws.ddbPutItem, aws.ddbUpdateItem, aws.ddbDeleteItem and aws.ddbQueryItem
- options may contain any valid native property if it starts with capital letter.
- Source:
Example
{ op: "put": table: "table-name", query: { id: 1, name: "tt" } },
{ op: "del": table: "table-name", query: { id: 2 } },
{ op: "update": table: "table-name", query: { id: 1, name: "test" }, options: { query: { status: "ok" } } },
{ op: "check": table: "table-name", query: { id: 1 }, options: { query: { status: "ok" } } }
(static) ddbUpdateItem()
- Description:
Update an item
- keys is an object with primary key attributes name and value.
- item is an object with properties where value can be:
- number/string/array - action PUT, replace or add new value
- null/empty string - action DELETE
- item can be a string with Update expression
- options may contain any valid native property if it starts with capital letter or special properties:
- expr - condition expression
- values - an object with values map to be used for in the update and/or condition expressions, to be used for ExpressionAttributeValues parameters
- names - an object with a map to be used for attribute names in condition and update expressions, to be used for ExpressionAttributeNames parameter
- ops - an object with operators to be used for properties, one of the: set, remove, unset, delete, incr, add, append, prepend, not_exists
- query - an object with columns to be used in ConditionExpression, value null means the attribute does not exists,
any other value to be checked against using regular compare rules. The conditional comparison operator is taken
from
options.opsthe same way as for queries. - returning - values to be returned on success,
*ornewmeans ALL_NEW,oldmeans ALL_OLD,updatedmeans UPDATED_NEW,old_updatedmeans UPDATED_OLD
- Source:
Example
ddbUpdateItem("users", { id: 1, name: "john" }, { gender: 'male', icons: '1.png' }, { action: { icons: 'add' }, query: { id: 1 }, returning: "*" })
ddbUpdateItem("users", { id: 1, name: "john" }, { gender: 'male', icons: '1.png' }, { action: { icons: 'incr' }, query: { id: null } })
ddbUpdateItem("users", { id: 1, name: "john" }, { gender: 'male', icons: '1.png', num: 1 }, { action: { num: 'add', icons: 'add' }, query: { id: null, num: 0 }, ops: { num: "gt" } })
(static) ddbUpdateTable()
- Description:
Update tables provisioned throughput settings, options is used instead of table name so this call can be used directly in the cron jobs to adjust provisionined throughput on demand. Options must provide the following properties:
- name - table name
- readCapacity and writeCapacity - new povisioned throughtput settings, both must be specified
- stream - null to disable or one of the NEW_IMAGE | OLD_IMAGE | NEW_AND_OLD_IMAGES | KEYS_ONLY
- add - an object with indexes to create
- del - delete a global secondary index by name, a string or a list with multiple indexes
- update - an object with indexes to update
- waitTimeout - how long to wait in ms until the table is active again
- onDemand - true to switch to pat per request mode, false to switch to provisioning mode
- Source:
Examples
aws.ddbUpdateTable({ name: "users", add: { name_id: { name: "S", id: 'N', readCapacity: 20, writeCapacity: 20, projections: ["mtime","email"] } })
aws.ddbUpdateTable({ name: "users", add: { name: { name: "S", readCapacity: 20, writeCapacity: 20, projections: ["mtime","email"] } })
aws.ddbUpdateTable({ name: "users", del: "name" })
aws.ddbUpdateTable({ name: "users", update: { name: { readCapacity: 10, writeCapacity: 10 } })
of crontab job in etc/crontab:
[
{ "cron": "0 0 1 * * *", "job": { "aws.ddbUpdateTable": { "name": "bk_user", "readCapacity": 1000, "writeCapacity": 1000 } } },
{ "cron": "0 0 6 * * *", "job": { "aws.ddbUpdateTable": { "name": "bk_user", "readCapacity": 2000, "writeCapacity": 2000 } } }
]
(static) ddbUpdateTimeToLive()
- Description:
Update TTL attribute. The options properties:
- name - table name
- attribute - the attribute name
- enabled - true or false
- Source:
(static) ddbWaitForTable()
- Description:
Call the callback after specified period of time or when table status become different from the given waiting status. if options.waitTimeout is not specified calls the callback immediately. options.waitStatus is checked if given and keeps waiting while the status is equal to it. options.waitDelay can be specified how often to request new status, default is 250ms.
- Source:
(static) detectLabels()
- Description:
Detect image features using AWS Rekognition service, the
namecan be a Buffer, a local file or an url to the S3 bucket. In the latter case the url can be just apath to the file inside a bucket ifoptions.bucketis specified, otherwise it must be a public S3 url with the bucket name to be the first part of the host name. For CDN/CloudFront cases use theoption.bucketoption.
- Source:
(static) ec2AssociateAddress()
- Description:
Associate an Elastic IP with an instance. Default behaviour is to reassociate if the EIP is taken. The options can specify the following:
- subnetId - required for instances in VPC, allocation id will be retrieved for the given ip address automatically
- Source:
(static) ec2AttachNetworkInterface()
- Description:
Attach given ENIs in
eniIdto theinstance, each ENI can be specified as 'eni:idx' where idx is interface index
- Source:
(static) ec2CreateImage()
- Description:
Create an EBS image from the instance given or the current instance running
- Source:
(static) ec2CreateTags()
- Description:
Create tags for a resource. The name is a string, an array or an object with tags. The options also may contain tags property which is an object with tag key and value
Example
aws.ec2CreateTags("i-1234","My Instance", { tags: { tag2 : "val2", tag3: "val3" } } ) aws.ec2CreateTags("i-1234", { tag2: "val2", tag3: "val3" }) aws.ec2CreateTags("i-1234", [ "tag2", "val2", "tag3", "val3" ])
- Source:
(static) ec2DeregisterImage()
- Description:
Deregister an AMI by id. If
options.snapshotsis set, then delete all snapshots for this image as well
- Source:
(static) ec2DescribeInstances()
- Description:
Describe instances according to the query filters, returns a list with instances, the following properties can be used:
- vpcId - VPC to get instances from
- instanceId - list of instances to show only
- tagName - filter by tag name(s)
- tagKey - filter by tag key(s)
- groupName - filter by group name(s)
- stateName - instances state(s)
- filters - an object with filters to send as is
- Source:
(static) ec2DescribeSecurityGroups()
- Description:
Describe security groups, optionally if
options.filterregexp is provided then limit the result to the matched groups only, return list of groups to the callback
- Source:
(static) ec2DescribeSubnets()
- Description:
Describe VPC subnets, optionally if
options.filterregexp is provided then limit the result to the matched subnets only, return list of subnets to the callback
- Source:
(static) ec2RunInstances()
- Description:
Run AWS instances, supports all native EC2 parameters with first capital letter but also accepts simple parameters in the options:
- min - min number of instances to run, default 1
- max - max number of instances to run, default 1
- imageId - AMI id, use aws.imageId if not given or options.ImageId attribute
- instanceType - instance type, use aws.instanceType if not given or options.InstanceType attribute
- keyName - Keypair, use aws.keyName if not given or options.KeyName attribute
- data - user data, in clear text
- terminate - set instance initiated shutdown behaviour to terminate
- stop - set instance initiated shutdown behaviour to stop
- groupId - one group id or an array with security group ids
- ip - a static private IP adress to assign
- publicIp - associate with a public IP address
- file - pass contents of a file as user data, contents are read using sync method
- noPrepare - even with additional tasks specified do not wai but return the context for aws.ec2PrepareInstance
- waitTimeout - how long to wait in ms for instance to be runnable
- waitDelay - now often in ms to poll for status while waiting
- waitRunning - if 1 then wait for instance to be in running state, this is implied also by targetGroup, name, elasticIp properties in the options
- name - assign a tag to the instance as
Name:, any occurences of %i will be replaced with the instance index - tags - additional tags to be assigned, an object with key:value
- targetGroup - join ELB target groups after the startup
- elasticIp - asociate with the given Elastic IP address after the start
- iamProfile - IAM profile to assign for instance credentials, if not given use aws.iamProfile or options['IamInstanceProfile.Name'] attribute
- availabilityZone - availability zone, if not given use aws.zone or options['Placement.AvailabilityZone'] attribute
- subnetId - subnet id, if not given use aws.subnetId or options.SubnetId attribute
- alarms - a list with CloudWatch alarms to create for the instance, each value of the object represent an object with options to be passed to the cwPutMetricAlarm method.
- device - an object for BlockDeviceMapping specification: { name, size, type, iosp, keep, virtual }
- metadata - list of metadata options: disabled, hops, tokens, tags
- launchTemplate - launch template name to use, latest version, all other options are ignored
The callback will take 3 arguments: callback(err, rc, info) where info will contain properties that can be used by `aws.ec2PrepareInstance
- Source:
(static) ec2WaitForInstance()
- Description:
Check an instance status and keep waiting until it is equal what we expect or timeout occurred. The
statuscan be one of: pending | running | shutting-down | terminated | stopping | stopped The options can specify the following:- waitTimeout - how long to wait in ms until give up, default is 30 secs
- waitDelay - how long in ms between polls
- Source:
(static) ecsDescribeTasks()
- Source:
(static) ecsPrepareTask()
- Source:
(static) ecsRunTask()
- Source:
(static) ecsTaskProtection()
- Source:
(static) elb2DeregisterInstances()
- Description:
Deregister an instance(s) from ELB, instance can be one id or a list of ids
- Source:
(static) elb2RegisterInstances()
- Description:
Register an instance(s) with ELB, instance can be one id or a list of ids or IP addresses
- Source:
(static) fromDynamoDB()
- Description:
Convert a DynamoDB object into Javascript object
- Source:
(static) getInstanceCredentials()
- Description:
Retrieve instance credentials using EC2 instance profile and setup for AWS access
- Source:
(static) getInstanceDetails()
- Description:
Get the current instance details if not retrieved already in
aws.instance
- Source:
(static) getInstanceInfo()
- Description:
Retrieve instance launch index from the meta data if running on AWS instance
- Source:
(static) getInstanceMeta()
- Description:
Retrieve instance meta data
- Source:
(static) getInstanceMetaToken()
- Source:
(static) getSecretValue(name, optionsopt, callback)
- Description:
Get a secret value from the Secrets Manager
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
name |
String | ||
options |
object |
<optional> |
|
callback |
function |
(static) getTaskDetails()
- Description:
If running inside ECS pulls the task details
- Source:
(static) listCertificates()
- Description:
Return a list of certificates,
statuscan limit which certs to return, PENDING_VALIDATION | ISSUED | INACTIVE | EXPIRED | VALIDATION_TIMED_OUT | REVOKED | FAILED
- Source:
(static) parseXMLResponse()
- Description:
Parse AWS response and try to extract error code and message, convert XML into an object.
- Source:
(static) queryACM()
(static) queryAS()
(static) queryAWS(region, service, proto, host, path, obj, options, callback)
- Description:
Make AWS request, return parsed response as Javascript object or null in case of error
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
region |
string | The AWS region (e.g., 'us-east-1'). |
service |
string | The AWS service name (e.g., 's3', 'ec2'). |
proto |
string | The protocol to use (e.g., 'https:', 'http:'). |
host |
string | The hostname for the request. |
path |
string | The path for the request. |
obj |
object | The object containing key-value pairs to be sent as parameters. |
options |
object | Additional options for the query. |
callback |
function | The callback function to handle the response. |
(static) queryCFN(action, obj, options, callback)
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
action |
string | The CloudFormation API action to perform (e.g., |
||||||||||||||||
obj |
Object | API-specific parameters as an object. |
||||||||||||||||
options |
Object | Optional configuration object Properties
|
||||||||||||||||
callback |
function | Callback function with:
signature
|
Example
```js
aws.queryCFN(
'CreateStack',
{StackName: 'MyStack', Body: stackTemplate}, // obj
{region: 'us-west-2'}, // options
(err, result) => { ... } // callback
)
(static) queryCW()
(static) queryCWL()
(static) queryComprehend()
(static) queryDDB()
- Description:
DynamoDB requests
- Source:
(static) queryEC2()
- Description:
AWS EC2 API request
- Source:
(static) queryECR()
(static) queryECS()
- Description:
AWS ECS API request
- Source:
(static) queryELB2()
- Source:
(static) queryElastiCache()
(static) queryEndpoint(service, version, action, obj, options, callback)
- Description:
AWS generic query interface
- Source:
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
service |
string | AWS service name |
||||||||||||||||
version |
string | Service version |
||||||||||||||||
action |
string | API-specific action to perform (e.g., |
||||||||||||||||
obj |
Object | API-specific parameters as an object. |
||||||||||||||||
options |
Object | Optional configuration object Properties
|
||||||||||||||||
callback |
function | Callback function with:
signature
|
(static) queryEvents()
(static) queryIAM()
(static) queryPrepare(action, version, obj, optionsopt) → {Object.<string, *>}
- Description:
Return a request object ready to be sent to AWS, properly formatted.
Builds a base request with
{ Action, Version }, copies all enumerable properties fromobj, then overlays anyoptionsproperties whose names start with an uppercase letter (A-Z). Uppercaseoptionskeys take priority and overwrite same-named keys fromobj.optionskeys are only applied if their value is notundefined,null, or an empty string.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
string | AWS API action name (e.g. |
|
version |
string | AWS API version string (e.g. |
|
obj |
Object.<string, *> | Request parameters to include in the AWS query. |
|
options |
Object.<string, *> |
<optional> |
Extra parameters; any keys starting with A-Z are copied as-is and override |
Returns:
| Type | Description |
|---|---|
| Object.<string, *> |
Request object ready to be sent to AWS. |
(static) queryRekognition()
(static) queryRoute53()
- Description:
Make a request to Route53 service
- Source:
(static) queryRoute53Domains()
- Source:
(static) queryS3(bucket, path, optionsopt)
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
bucket |
string | ||
path |
string | ||
options |
object |
<optional> |
|
(static) querySES()
- Description:
AWS SES API request
- Source:
(static) querySNS()
- Description:
AWS SNS API request
- Source:
(static) querySQS()
- Description:
AWS SQS API request
- Source:
(static) querySSM()
(static) querySTS()
(static) querySecrets()
(static) queryService(endpoint, target, action, obj, optionsopt, callback)
- Description:
Executes an AWS service query for the specified action
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
endpoint |
string | AWS service endpoint (e.g., 'asm', 'ecr', ...) |
|
target |
string | Namespace for the AWS service API (e.g., 'AmazonSSM', 'CertificateManager') |
|
action |
string | AWS API action to perform (e.g., 'PutItem', 'GetItem') |
|
obj |
Object | Request body object containing action parameters |
|
options |
Object |
<optional> |
Optional configuration options:
|
callback |
function | Callback function with signature: (err, response) where err contains the error (if any) and response contains:
|
Example
aws.queryService("ecs", "AmazonEC2ContainerServiceV20141113", 'DescribeTasks', {
cluster: 'MyCluster',
}, (err, response) => { ... });
(static) querySign(region, service, host, method, path, body, headers, credentialsopt, optionsopt) → {void}
- Description:
Build AWS Signature Version 4 headers for a request.
Populates/overwrites required signing headers in
headers(e.g.host,x-amz-date, optionalcontent-type,content-length,x-amz-security-token) and setsheaders.Authorization. Ifoptionsis provided, signing details are also written into it.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
region |
string | AWS region (e.g. |
|||||||||||||||||||||||||
service |
string | AWS service name (e.g. |
|||||||||||||||||||||||||
host |
string | Request host (e.g. |
|||||||||||||||||||||||||
method |
string | HTTP method (e.g. |
|||||||||||||||||||||||||
path |
string | Request path, may include query string (e.g. |
|||||||||||||||||||||||||
body |
string | Buffer | null | Request payload. If provided, will be hashed for signing and may
set |
|||||||||||||||||||||||||
headers |
Object.<string, (string|number|boolean)> | Mutable headers object to sign; updated in-place. |
|||||||||||||||||||||||||
credentials |
Object |
<optional> |
AWS credentials to use; defaults to Properties
|
||||||||||||||||||||||||
options |
Object |
<optional> |
Optional output/input options. Properties
|
Returns:
| Type | Description |
|---|---|
| void |
(static) queryTranscribe()
(static) readConfig()
- Description:
Read and apply configs from S3 bucket, AWS SecretsManager, AWS Systems Manager
- Source:
Examples
Use config from S3 bucket, different for each run mode, running `-app-roles production` and `-app-roles dev` will use different config files
# local config pointing to S3 config bkjs-aws.conf when running in AWS env or bkjs-dev.conf otherwise
aws-config-s3-file = s3://mybucket/config/bkjs-@type|dev@.conf
# bkjs-production.conf: production config on S3
[roles=production]
db-dynamodb-pool = default
db-pool = dynamodb
app-log-level = info
# bkjs-dev.conf: development config on S3
[roles=dev]
db-dynamodb-pool = http://localhost:8181
db-pool = dynamodb
app-log-level = debug
Use secrets manager for api keys, different for dev and prod
# local config pointing to secrets manager
aws-config-secrets = bkjs-@runMode@
# store 2 secrets as
aws secretsmanager create-secret --name bkjs-production --secret-string "my-secret = 12345\nmy-api-key = 9887"
aws secretsmanager create-secret --name bkjs-dev --secret-string "my-secret = 0000\nmy-api-key = 00000"
(static) readCredentials()
- Description:
Read key and secret from the AWS SDK credentials file, if no profile is given in the config or command line only the default peofile will be loaded.
- Source:
(static) route53Change()
- Description:
Create or update a host in the Route53 database.
namesis a host name to be set with the current IP address or a list with objects in the format [ { name: "..", value: "1.1.1.1", type: "A", ttl: 300, zoneId: "Id", alias: "dnsname", hostedzone: "/hostedzone/id" } ...]
The
optionsmay contain the following:- type - default record type, A
- ttl - default TTL, 300 seconds
- op - an operation, default is UPSERT
- Source:
(static) route53Create()
- Source:
(static) route53Get()
- Description:
Return a zone by domain or id
- Source:
(static) route53List()
- Description:
List all zones
- Source:
(static) s3CopyFile(path, source, optionsopt)
- Description:
Copy existing S3 file, source must be in the format
bucket/path
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
string | ||
source |
string | ||
options |
object |
<optional> |
(static) s3GetFile(path, optionsopt)
- Description:
Retrieve a file from S3 bucket, root of the path is a bucket, path can have a protocol prepended like s3://, it will be ignored
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
string | ||
options |
object |
<optional> |
(static) s3List(path, optionsopt)
- Description:
Retrieve a list of files from S3 bucket, only files inside the path will be returned
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
string | ||
options |
object |
<optional> |
(static) s3ParseUrl()
(static) s3Proxy(res, bucket, file, optionsopt, callbackopt)
- Description:
Proxy (stream) an object from an S3 bucket into an existing HTTP response.
Typically used to serve/download S3-hosted files through your app: it fetches
filefrombucket(optionally using request options like range/content-type/etc) and pipes the S3 response directly intores, preserving status/headers as appropriate.
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
res |
http.ServerResponse | Node.js HTTP response object to write to. The S3 object data is streamed into it. |
|||||||||||||
bucket |
string | S3 bucket name that contains the object. |
|||||||||||||
file |
string | S3 object key (path inside the bucket). |
|||||||||||||
options |
Object |
<optional> |
Controls how the object is fetched and how the HTTP response is produced. Properties
|
||||||||||||
callback |
function |
<optional> |
Called when proxying finishes or fails.
|
(static) s3PutFile(path, file, optionsopt)
- Description:
Upload a file to S3 bucket,
filecan be a Buffer or a file name
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
path |
string | ||
file |
string | ||
options |
object |
<optional> |
(static) sesSendEmail()
- Description:
Send an email via SES The following options supported:
- from - an email to use in the From: header
- cc - list of email to use in CC: header
- bcc - list of emails to use in Bcc: header
- replyTo - list of emails to ue in ReplyTo: header
- returnPath - email where to send bounces
- charset - charset to use, default is UTF-8
- html - if set the body is sent as MIME HTML
- config - configuration set name
- Source:
(static) sesSendRawEmail(body, optionsopt)
- Description:
SES V1 send raw email
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
body |
string | base64 encoded raw mail envelope |
|||||||||||||||||
options |
object |
<optional> |
Properties
|
(static) sesSendRawEmail2(body, optionsopt)
- Description:
SES V2 version Send raw email
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
body |
string | base64 encoded raw mail envelope |
|||||||||||||||||
options |
object |
<optional> |
Properties
|
(static) signS3(method, bucket, body, optionsopt)
- Description:
Sign S3 AWS request, returns url to be send to S3 server, options will have all updated headers to be sent as well
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
method |
string | HTTP method, GET is default |
|
bucket |
string | ||
|
path | ||
body |
string | Buffer | ||
options |
object |
<optional> |
(static) snsConfirmSubscription()
- Description:
Verifies an endpoint owner's intent to receive messages by validating the token sent to the endpoint by an earlier Subscribe action. If the token is valid, the action creates a new subscription and returns its Amazon Resource Name (ARN) in the callback.
- Source:
(static) snsCreatePlatformEndpoint()
- Description:
Creates an endpoint for a device and mobile app on one of the supported push notification services, such as GCM and APNS.
The following properties can be specified in the options:
- appArn - an application ARN to be used for push notifications, if not passed, global
-sns-app-arnwill be used. - data - a user data to be associated with the endpoint arn
All capitalized properties in the options will be pased as is. The callback will be called with an error if any and the endpoint ARN
- appArn - an application ARN to be used for push notifications, if not passed, global
- Source:
(static) snsCreateTopic()
- Description:
Creates a topic to which notifications can be published. The callback returns topic ARN on success.
- Source:
(static) snsDeleteEndpoint()
- Description:
Deletes the endpoint from Amazon SNS.
- Source:
(static) snsDeleteTopic()
- Description:
Deletes the topic from Amazon SNS.
- Source:
(static) snsListTopics()
- Description:
Creates a topic to which notifications can be published. The callback returns topic ARN on success.
- Source:
(static) snsPublish()
- Description:
Sends a message to all of a topic's subscribed endpoints or to a mobile endpoint. If msg is an object, then it will be pushed as JSON. The options may take the following properties:
- subject - optional subject to be included in the message if the target supports it
- Source:
(static) snsSetEndpointAttributes()
- Description:
Sets the attributes for an endpoint for a device on one of the supported push notification services, such as GCM and APNS.
The following properties can be specified in the options:
- token - a device token for the notification service
- data - a user data to be associated with the endpoint arn
- enabled - true or false to enable/disable the deliver of notifications to this endpoint
- Source:
(static) snsSetSubscriptionAttributes()
- Description:
Updates the subscription attributes. The following options can be used:
- name - new topic name
- deliveryPolicy - an object with delivery attributes, can specify all or only the ones that needed to be updated
- minDelayTarget - update delivery policy by attribute name
- maxDelayTarget
- numRetries
- numMaxDelayRetries
- backoffFunction - one of linear|arithmetic|geometric|exponential
- maxReceivesPerSecond
- Source:
(static) snsSetTopicAttributes()
- Description:
Updates the topic attributes. The following options can be used:
- name - new topic name
- policy - an object with access policy
- deliveryPolicy - an object with delivery attributes, can specify all or only the ones that needed to be updated
- Source:
(static) snsSubscribe()
- Description:
Creates a topic to which notifications can be published. The callback returns topic ARN on success, if the topic requires confirmation the arn returned will be null and a token will be sent to the endpoint for confirmation.
- Source:
(static) snsUnsubscribe()
- Description:
Creates a topic to which notifications can be published. The callback returns topic ARN on success.
- Source:
(static) sqsReceiveMessage()
- Description:
Receive message(s) from the SQS queue, the callback will receive a list with messages if no error. The following options can be specified:
- count - how many messages to receive
- timeout - how long to wait, in milliseconds, this is for Long Poll
- visibilityTimeout - the duration (in milliseconds) that the received messages are hidden from subsequent retrieve requests
- attempt - request attempt id for FIFO queues after being retrieved by a ReceiveMessage request.
- Source:
(static) sqsSendMessage()
- Description:
Send a message to the SQS queue. The options can specify the following:
- delay - how long to delay this message in milliseconds
- group - a group id for FIFO queues
- unique - deduplication id for FIFO queues
- attrs - an object with additional message attributes to send, use only string, numbers or binary values, all other types will be converted into strings
- Source:
(static) ssmGetParametersByPath(path, optionsopt, callback)
- Description:
Retrieve information about one or more parameters under a specified level in a hierarchy from AWS System Manager
- Source:
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
path |
string | The hierarchy for the parameter. Hierarchies start with a forward slash (/). The hierarchy is the parameter name except the last part of the parameter. For the API call to succeed, the last part of the parameter name can't be in the path. A parameter name hierarchy can have a maximum of 15 levels. Here is an example of a hierarchy: /Finance/Prod/IAD/WinServ2016/license33 |
|||||||||
options |
object |
<optional> |
Properties
|
||||||||
callback |
function |
(static) ssmSendCommand()
- Description:
Run a shell command
- Source:
(static) ssmWaitForCommand()
- Description:
Return a command details
- Source:
(static) stsAssumeRole()
- Description:
Assume a role and return new credentials that can be used in other API calls
- Source:
(static) toDynamoDB()
- Description:
Convert a Javascript object into DynamoDB object
- Source: