Skip to content

Commit

Permalink
feat(client-ec2): Adds support for waiters that automatically poll fo…
Browse files Browse the repository at this point in the history
…r a deleted NAT Gateway until it reaches the deleted state.
  • Loading branch information
awstools committed Apr 22, 2022
1 parent e7c061d commit 047c131
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 27 deletions.
16 changes: 16 additions & 0 deletions clients/client-ec2/src/EC2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20256,6 +20256,14 @@ export class EC2 extends EC2Client {
* supported.</p>
* <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html">Spot Fleet requests</a>
* in the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*
* <important>
* <p>We strongly discourage using the RequestSpotFleet API because it is a legacy
* API with no planned investment. For options for requesting Spot Instances, see
* <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-best-practices.html#which-spot-request-method-to-use">Which
* is the best Spot request method to use?</a> in the
* <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* </important>
*/
public requestSpotFleet(
args: RequestSpotFleetCommandInput,
Expand Down Expand Up @@ -20290,6 +20298,14 @@ export class EC2 extends EC2Client {
* <p>Creates a Spot Instance request.</p>
* <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html">Spot Instance requests</a> in
* the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*
* <important>
* <p>We strongly discourage using the RequestSpotInstances API because it is a legacy
* API with no planned investment. For options for requesting Spot Instances, see
* <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-best-practices.html#which-spot-request-method-to-use">Which
* is the best Spot request method to use?</a> in the
* <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* </important>
*/
public requestSpotInstances(
args: RequestSpotInstancesCommandInput,
Expand Down
8 changes: 8 additions & 0 deletions clients/client-ec2/src/commands/RequestSpotFleetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export interface RequestSpotFleetCommandOutput extends RequestSpotFleetResponse,
* supported.</p>
* <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html">Spot Fleet requests</a>
* in the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*
* <important>
* <p>We strongly discourage using the RequestSpotFleet API because it is a legacy
* API with no planned investment. For options for requesting Spot Instances, see
* <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-best-practices.html#which-spot-request-method-to-use">Which
* is the best Spot request method to use?</a> in the
* <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* </important>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export interface RequestSpotInstancesCommandOutput extends RequestSpotInstancesR
* <p>Creates a Spot Instance request.</p>
* <p>For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-requests.html">Spot Instance requests</a> in
* the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*
* <important>
* <p>We strongly discourage using the RequestSpotInstances API because it is a legacy
* API with no planned investment. For options for requesting Spot Instances, see
* <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-best-practices.html#which-spot-request-method-to-use">Which
* is the best Spot request method to use?</a> in the
* <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* </important>
* @example
* Use a bare-bones client and the command you need to make an API call.
* ```javascript
Expand Down
9 changes: 8 additions & 1 deletion clients/client-ec2/src/models/models_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3483,7 +3483,14 @@ export namespace CreateKeyPairRequest {
*/
export interface KeyPair {
/**
* <p>The SHA-1 digest of the DER encoded private key.</p>
* <ul>
* <li>
* <p>For RSA key pairs, the key fingerprint is the SHA-1 digest of the DER encoded private key.</p>
* </li>
* <li>
* <p>For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with OpenSSH 6.8.</p>
* </li>
* </ul>
*/
KeyFingerprint?: string;

Expand Down
8 changes: 6 additions & 2 deletions clients/client-ec2/src/models/models_3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5482,6 +5482,11 @@ export interface DescribeInstancesRequest {
* </li>
* <li>
* <p>
* <code>capacity-reservation-id</code> - The ID of the Capacity Reservation into which the
* instance was launched.</p>
* </li>
* <li>
* <p>
* <code>client-token</code> - The idempotency token you provided when you launched
* the instance.</p>
* </li>
Expand Down Expand Up @@ -8908,8 +8913,7 @@ export interface KeyPairInfo {
* <p>If you used <a>CreateKeyPair</a> to create the key pair:</p>
* <ul>
* <li>
* <p>For RSA key pairs, the key fingerprint is the SHA-1 digest of the DER encoded private key.
* </p>
* <p>For RSA key pairs, the key fingerprint is the SHA-1 digest of the DER encoded private key.</p>
* </li>
* <li>
* <p>For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which
Expand Down
10 changes: 5 additions & 5 deletions clients/client-ec2/src/models/models_4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,7 @@ export interface DescribeSpotInstanceRequestsRequest {
* <code>state</code> - The state of the Spot Instance request (<code>open</code>
* | <code>active</code> | <code>closed</code> | <code>cancelled</code> |
* <code>failed</code>). Spot request status information can help you track
* your Amazon EC2 Spot Instance requests. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-bid-status.html">Spot
* your Amazon EC2 Spot Instance requests. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-request-status.html">Spot
* request status</a> in the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* </li>
* <li>
Expand Down Expand Up @@ -4067,7 +4067,7 @@ export interface LaunchSpecification {
ImageId?: string;

/**
* <p>The instance type.</p>
* <p>The instance type. Only one instance type can be specified.</p>
*/
InstanceType?: _InstanceType | string;

Expand Down Expand Up @@ -4124,7 +4124,7 @@ export type SpotInstanceState = "active" | "cancelled" | "closed" | "failed" | "
*/
export interface SpotInstanceStatus {
/**
* <p>The status code. For a list of status codes, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-bid-status.html#spot-instance-bid-status-understand">Spot status codes</a> in the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
* <p>The status code. For a list of status codes, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-request-status.html#spot-instance-request-status-understand">Spot request status codes</a> in the <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*/
Code?: string;

Expand Down Expand Up @@ -4214,8 +4214,8 @@ export interface SpotInstanceRequest {
SpotPrice?: string;

/**
* <p>The state of the Spot Instance request. Spot status information helps track your Spot
* Instance requests. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-bid-status.html">Spot status</a> in the
* <p>The state of the Spot Instance request. Spot request status information helps track your Spot
* Instance requests. For more information, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-request-status.html">Spot request status</a> in the
* <i>Amazon EC2 User Guide for Linux Instances</i>.</p>
*/
State?: SpotInstanceState | string;
Expand Down
18 changes: 12 additions & 6 deletions clients/client-ec2/src/models/models_5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3073,7 +3073,14 @@ export namespace ImportKeyPairRequest {

export interface ImportKeyPairResult {
/**
* <p>The MD5 public key fingerprint as specified in section 4 of RFC 4716.</p>
* <ul>
* <li>
* <p>For RSA key pairs, the key fingerprint is the MD5 public key fingerprint as specified in section 4 of RFC 4716.</p>
* </li>
* <li>
* <p>For ED25519 key pairs, the key fingerprint is the base64-encoded SHA-256 digest, which is the default for OpenSSH, starting with <a href="http://www.openssh.com/txt/release-6.8">OpenSSH 6.8</a>.</p>
* </li>
* </ul>
*/
KeyFingerprint?: string;

Expand Down Expand Up @@ -6224,10 +6231,9 @@ export interface ModifySubnetAttributeRequest {
EnableDns64?: AttributeBooleanValue;

/**
* <p>The type of hostnames to assign to instances in the subnet at launch. For IPv4 only subnets, an
* instance DNS name must be based on the instance IPv4 address. For IPv6 only subnets, an instance
* DNS name must be based on the instance ID. For dual-stack subnets, you can specify whether DNS
* names use the instance IPv4 address or the instance ID.</p>
* <p>The type of hostname to assign to instances in the subnet at launch. For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an
* instance DNS name can be based on the instance IPv4 address (ip-name) or the instance ID (resource-name). For IPv6 only subnets, an instance
* DNS name must be based on the instance ID (resource-name).</p>
*/
PrivateDnsHostnameTypeOnLaunch?: HostnameType | string;

Expand Down Expand Up @@ -9702,7 +9708,7 @@ export interface RequestSpotLaunchSpecification {
ImageId?: string;

/**
* <p>The instance type.</p>
* <p>The instance type. Only one instance type can be specified.</p>
*/
InstanceType?: _InstanceType | string;

Expand Down
3 changes: 3 additions & 0 deletions clients/client-ec2/src/models/models_6.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SENSITIVE_STRING } from "@aws-sdk/smithy-client";

import {
_InstanceType,
AddressAttribute,
Expand Down Expand Up @@ -1501,6 +1503,7 @@ export namespace RunInstancesRequest {
*/
export const filterSensitiveLog = (obj: RunInstancesRequest): any => ({
...obj,
...(obj.UserData && { UserData: SENSITIVE_STRING }),
});
}

Expand Down
1 change: 1 addition & 0 deletions clients/client-ec2/src/waiters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export * from "./waitForInstanceTerminated";
export * from "./waitForInternetGatewayExists";
export * from "./waitForKeyPairExists";
export * from "./waitForNatGatewayAvailable";
export * from "./waitForNatGatewayDeleted";
export * from "./waitForNetworkInterfaceAvailable";
export * from "./waitForSecurityGroupExists";
export * from "./waitForSnapshotCompleted";
Expand Down
58 changes: 58 additions & 0 deletions clients/client-ec2/src/waiters/waitForNatGatewayDeleted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@aws-sdk/util-waiter";

import { DescribeNatGatewaysCommand, DescribeNatGatewaysCommandInput } from "../commands/DescribeNatGatewaysCommand";
import { EC2Client } from "../EC2Client";

const checkState = async (client: EC2Client, input: DescribeNatGatewaysCommandInput): Promise<WaiterResult> => {
let reason;
try {
const result: any = await client.send(new DescribeNatGatewaysCommand(input));
reason = result;
try {
const returnComparator = () => {
const flat_1: any[] = [].concat(...result.NatGateways);
const projection_3 = flat_1.map((element_2: any) => {
return element_2.State;
});
return projection_3;
};
let allStringEq_5 = returnComparator().length > 0;
for (const element_4 of returnComparator()) {
allStringEq_5 = allStringEq_5 && element_4 == "deleted";
}
if (allStringEq_5) {
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "NatGatewayNotFound") {
return { state: WaiterState.SUCCESS, reason };
}
}
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated Use waitUntilNatGatewayDeleted instead. waitForNatGatewayDeleted does not throw error in non-success cases.
*/
export const waitForNatGatewayDeleted = async (
params: WaiterConfiguration<EC2Client>,
input: DescribeNatGatewaysCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 15, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params - Waiter configuration options.
* @param input - The input to DescribeNatGatewaysCommand for polling.
*/
export const waitUntilNatGatewayDeleted = async (
params: WaiterConfiguration<EC2Client>,
input: DescribeNatGatewaysCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 15, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};
53 changes: 40 additions & 13 deletions codegen/sdk-codegen/aws-models/ec2.json

Large diffs are not rendered by default.

0 comments on commit 047c131

Please sign in to comment.