Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@aws-sdk/util-waiter
Advanced tools
@aws-sdk/util-waiter is a utility package in the AWS SDK for JavaScript that provides functionality to wait for a resource to reach a desired state. This is particularly useful for operations that are asynchronous and may take some time to complete, such as creating or deleting AWS resources.
Wait for a resource to reach a desired state
This feature allows you to wait until a DynamoDB table exists. The `waitUntilTableExists` function polls the `DescribeTableCommand` until the table reaches the 'ACTIVE' state or the maximum wait time is reached.
const { DynamoDBClient, DescribeTableCommand } = require('@aws-sdk/client-dynamodb');
const { waitUntilTableExists } = require('@aws-sdk/util-waiter');
const client = new DynamoDBClient({ region: 'us-west-2' });
const params = { TableName: 'my-table' };
const run = async () => {
try {
const result = await waitUntilTableExists({ client, maxWaitTime: 300 }, { TableName: 'my-table' });
console.log('Table exists:', result);
} catch (error) {
console.error('Error waiting for table to exist:', error);
}
};
run();
Custom waiters
This feature allows you to create custom waiters for any AWS resource. In this example, a custom waiter is created to wait until an EC2 instance is in the 'running' state.
const { EC2Client, DescribeInstancesCommand } = require('@aws-sdk/client-ec2');
const { createWaiter, WaiterState } = require('@aws-sdk/util-waiter');
const client = new EC2Client({ region: 'us-west-2' });
const checkInstanceRunning = async () => {
const command = new DescribeInstancesCommand({ InstanceIds: ['i-1234567890abcdef0'] });
const result = await client.send(command);
const instance = result.Reservations[0].Instances[0];
return instance.State.Name === 'running' ? { state: WaiterState.SUCCESS } : { state: WaiterState.RETRY };
};
const run = async () => {
try {
const result = await createWaiter({ client, maxWaitTime: 300 }, checkInstanceRunning);
console.log('Instance is running:', result);
} catch (error) {
console.error('Error waiting for instance to run:', error);
}
};
run();
The `promise-retry` package provides a way to retry a function that returns a promise until it succeeds or a maximum number of retries is reached. Unlike @aws-sdk/util-waiter, it is not specific to AWS resources and can be used for any asynchronous operation.
The `async-retry` package is another utility for retrying asynchronous operations. It allows you to specify retry strategies and is more flexible in terms of configuration compared to @aws-sdk/util-waiter, but it does not provide built-in support for AWS resource states.
3.341.0 (2023-05-26)
FAQs
Shared utilities for client waiters for the AWS SDK
The npm package @aws-sdk/util-waiter receives a total of 1,133,924 weekly downloads. As such, @aws-sdk/util-waiter popularity was classified as popular.
We found that @aws-sdk/util-waiter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 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
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.