forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ec2): lookup available AZs for Interface Endpoints
This commit adds a new context provider which will make a DescribeVpcEndpointServices call to figure out what AZs are available. This will filter the user-provided `subnets` parameter to only include subnets for the AZs discovered through DescribeVpcEndpointServices.
- Loading branch information
1 parent
0f948a4
commit 9fa3221
Showing
11 changed files
with
268 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/cloud-assembly-schema/schema/cloud-assembly.version.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"2.0.0"} | ||
{"version":"3.0.0"} |
26 changes: 26 additions & 0 deletions
26
packages/@aws-cdk/cx-api/lib/context/endpoint-service-availability-zones.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export const ENDPOINT_SERVICE_AVAILABILITY_ZONE_PROVIDER = 'endpoint-service-availability-zones'; | ||
|
||
/** | ||
* Query to hosted zone context provider | ||
*/ | ||
export interface EndpointServiceAvailabilityZonesContextQuery { | ||
/** | ||
* Query account | ||
*/ | ||
readonly account?: string; | ||
|
||
/** | ||
* Query region | ||
*/ | ||
readonly region?: string; | ||
|
||
/** | ||
* Query service name | ||
*/ | ||
readonly serviceName?: string; | ||
} | ||
|
||
/** | ||
* Response of the AZ provider looks like this | ||
*/ | ||
export type EndpointServiceAvailabilityZonesContextResponse = string[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
packages/aws-cdk/lib/context-providers/endpoint-service-availability-zones.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as cxapi from '@aws-cdk/cx-api'; | ||
import { Mode, SdkProvider } from '../api'; | ||
import { debug } from '../logging'; | ||
import { ContextProviderPlugin } from './provider'; | ||
|
||
/** | ||
* Plugin to retrieve the Availability Zones for an endpoint service | ||
*/ | ||
export class EndpointServiceAZContextProviderPlugin implements ContextProviderPlugin { | ||
constructor(private readonly aws: SdkProvider) { | ||
} | ||
|
||
public async getValue(args: {[key: string]: any}) { | ||
const region = args.region; | ||
const account = args.account; | ||
const serviceName = args.serviceName; | ||
debug(`Reading AZs for ${account}:${region}:${serviceName}`); | ||
const ec2 = (await this.aws.forEnvironment(cxapi.EnvironmentUtils.make(account, region), Mode.ForReading)).ec2(); | ||
const response = await ec2.describeVpcEndpointServices({ServiceNames: [serviceName]}).promise(); | ||
|
||
// expect a service in the response | ||
if (!response.ServiceDetails || response.ServiceDetails.length === 0) { | ||
debug(`Could not retrieve service details for ${account}:${region}:${serviceName}`); | ||
return []; | ||
} | ||
const azs = response.ServiceDetails[0].AvailabilityZones; | ||
debug(`Endpoint service ${account}:${region}:${serviceName} is available in availability zones ${azs}`); | ||
return azs; | ||
} | ||
} |
Oops, something went wrong.