Skip to content

Commit

Permalink
Merge branch 'main' into kaizencc-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jun 28, 2022
2 parents d47f9c1 + b1e6d62 commit d1c4f38
Show file tree
Hide file tree
Showing 28 changed files with 1,747 additions and 1,354 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.29.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.29.0-alpha.0...v2.29.1-alpha.0) (2022-06-24)

## [2.29.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.28.1-alpha.0...v2.29.0-alpha.0) (2022-06-22)

## [2.28.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.28.0-alpha.0...v2.28.1-alpha.0) (2022-06-15)
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.29.1](https://github.com/aws/aws-cdk/compare/v2.29.0...v2.29.1) (2022-06-24)


### Bug Fixes

* **pipelines:** 'ConfirmPermissionsBroadening' uses wrong node version ([#20861](https://github.com/aws/aws-cdk/issues/20861)) ([47b5ca0](https://github.com/aws/aws-cdk/commit/47b5ca06c50a566af8d1fed4202164b85f793d18))

## [2.29.0](https://github.com/aws/aws-cdk/compare/v2.28.1...v2.29.0) (2022-06-22)


Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export class Stage extends Resource implements IStage {
};

// if any of them are defined, add an entry for '/*/*'.
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x).length > 0;
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x !== undefined).length > 0;
if (hasCommonOptions) {
settings.push(renderEntry('/*/*', commonMethodOptions));
}
Expand Down
27 changes: 27 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/stage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Template } from '@aws-cdk/assertions';
import * as logs from '@aws-cdk/aws-logs';
import * as cdk from '@aws-cdk/core';
import * as apigateway from '../lib';
import { ApiDefinition } from '../lib';

describe('stage', () => {
test('minimal setup', () => {
Expand Down Expand Up @@ -396,4 +397,30 @@ describe('stage', () => {
accessLogFormat: testFormat,
})).toThrow(/Access log format is specified without a destination/);
});

test('default throttling settings', () => {
// GIVEN
const stack = new cdk.Stack();
new apigateway.SpecRestApi(stack, 'testapi', {
apiDefinition: ApiDefinition.fromInline({
openapi: '3.0.2',
}),
deployOptions: {
throttlingBurstLimit: 0,
throttlingRateLimit: 0,
metricsEnabled: false,
},
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', {
MethodSettings: [{
DataTraceEnabled: false,
HttpMethod: '*',
ResourcePath: '/*',
ThrottlingBurstLimit: 0,
ThrottlingRateLimit: 0,
}],
});
});
});
53 changes: 53 additions & 0 deletions packages/@aws-cdk/aws-appmesh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ const mesh = new appmesh.Mesh(this, 'AppMesh', {
});
```

A mesh with an IP preference can be created by providing the property `serviceDiscovery` that specifes an `ipPreference`.

```ts
const mesh = new appmesh.Mesh(this, 'AppMesh', {
meshName: 'myAwsMesh',
serviceDiscovery: {
ipPreference: appmesh.IpPreference.IPV4_ONLY,
},
});
```

## Adding VirtualRouters

A _mesh_ uses _virtual routers_ as logical units to route requests to _virtual nodes_.
Expand Down Expand Up @@ -425,6 +436,48 @@ const gateway = new appmesh.VirtualGateway(this, 'gateway', {
});
```

### Adding an IP Preference to a Virtual Node

An `ipPreference` can be specified as part of a Virtual Node's service discovery. An IP preference defines how clients for this Virtual Node will interact with it.

There a four different IP preferences available to use which each specify what IP versions this Virtual Node will use and prefer.

- `IPv4_ONLY` - Only use IPv4. For CloudMap service discovery, only IPv4 addresses returned from CloudMap will be used. For DNS service discovery, Envoy's DNS resolver will only resolve DNS queries for IPv4.

- `IPv4_PREFERRED` - Prefer IPv4 and fall back to IPv6. For CloudMap service discovery, an IPv4 address will be used if returned from CloudMap. Otherwise, an IPv6 address will be used if available. For DNS service discovery, Envoy's DNS resolver will first attempt to resolve DNS queries using IPv4 and fall back to IPv6.

- `IPv6_ONLY` - Only use IPv6. For CloudMap service discovery, only IPv6 addresses returned from CloudMap will be used. For DNS service discovery, Envoy's DNS resolver will only resolve DNS queries for IPv6.

- `IPv6_PREFERRED` - Prefer IPv6 and fall back to IPv4. For CloudMap service discovery, an IPv6 address will be used if returned from CloudMap. Otherwise, an IPv4 address will be used if available. For DNS service discovery, Envoy's DNS resolver will first attempt to resolve DNS queries using IPv6 and fall back to IPv4.

```ts
const mesh = new appmesh.Mesh(stack, 'mesh', {
meshName: 'mesh-with-preference',
});

// Virtual Node with DNS service discovery and an IP preference
const dnsNode = new appmesh.VirtualNode(stack, 'dns-node', {
mesh,
serviceDiscovery: appmesh.ServiceDiscovery.dns('test', appmesh.DnsResponseType.LOAD_BALANCER, appmesh.IpPreference.IPV4_ONLY),
});

// Virtual Node with CloudMap service discovery and an IP preference
const vpc = new ec2.Vpc(stack, 'vpc');
const namespace = new cloudmap.PrivateDnsNamespace(stack, 'test-namespace', {
vpc,
name: 'domain.local',
});
const service = namespace.createService('Svc');

const instanceAttribute : { [key: string]: string} = {};
instanceAttribute.testKey = 'testValue';

const cloudmapNode = new appmesh.VirtualNode(stack, 'cloudmap-node', {
mesh,
serviceDiscovery: appmesh.ServiceDiscovery.cloudMap(service, instanceAttribute, appmesh.IpPreference.IPV4_ONLY),
});
```

## Adding a Route

A _route_ matches requests with an associated virtual router and distributes traffic to its associated virtual nodes.
Expand Down
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-appmesh/lib/mesh.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnMesh } from './appmesh.generated';
import { MeshServiceDiscovery } from './service-discovery';
import { VirtualGateway, VirtualGatewayBaseProps } from './virtual-gateway';
import { VirtualNode, VirtualNodeBaseProps } from './virtual-node';
import { VirtualRouter, VirtualRouterBaseProps } from './virtual-router';
Expand Down Expand Up @@ -124,6 +125,13 @@ export interface MeshProps {
* @default DROP_ALL
*/
readonly egressFilter?: MeshFilterType;

/**
* Defines how upstream clients will discover VirtualNodes in the Mesh
*
* @default - No Service Discovery
*/
readonly serviceDiscovery?: MeshServiceDiscovery;
}

/**
Expand Down Expand Up @@ -187,6 +195,7 @@ export class Mesh extends MeshBase {
egressFilter: props.egressFilter ? {
type: props.egressFilter,
} : undefined,
serviceDiscovery: props.serviceDiscovery,
},
});

Expand Down
66 changes: 60 additions & 6 deletions packages/@aws-cdk/aws-appmesh/lib/service-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,52 @@ import * as cloudmap from '@aws-cdk/aws-servicediscovery';
import { Construct } from 'constructs';
import { CfnVirtualNode } from './appmesh.generated';

/**
* Enum of supported IP preferences.
* Used to dictate the IP version for mesh wide and virtual node service discovery.
* Also used to specify the IP version that a sidecar Envoy uses when sending traffic to a local application.
*/

export enum IpPreference {
/**
* Use IPv4 when sending traffic to a local application.
* Only use IPv4 for service discovery.
*/
IPV4_ONLY = 'IPv4_ONLY',
/**
* Use IPv4 when sending traffic to a local application.
* First attempt to use IPv4 and fall back to IPv6 for service discovery.
*/
IPV4_PREFERRED = 'IPv4_PREFERRED',
/**
* Use IPv6 when sending traffic to a local application.
* Only use IPv6 for service discovery.
*/
IPV6_ONLY = 'IPv6_ONLY',
/**
* Use IPv6 when sending traffic to a local application.
* First attempt to use IPv6 and fall back to IPv4 for service discovery.
*/
IPV6_PREFERRED = 'IPv6_PREFERRED'
}

/**
* Properties for Mesh Service Discovery
*/
export interface MeshServiceDiscovery {
/**
* IP preference applied to all Virtual Nodes in the Mesh
*
* @default - No IP preference is applied to any of the Virtual Nodes in the Mesh.
* Virtual Nodes without an IP preference will have the following configured.
* Envoy listeners are configured to bind only to IPv4.
* Envoy will use IPv4 when sending traffic to a local application.
* For DNS service discovery, the Envoy DNS resolver to prefer using IPv6 and fall back to IPv4.
* For CloudMap service discovery, App Mesh will prefer using IPv4 and fall back to IPv6 for IPs returned by CloudMap.
*/
readonly ipPreference?: IpPreference;
}

/**
* Properties for VirtualNode Service Discovery
*/
Expand Down Expand Up @@ -48,9 +94,10 @@ export abstract class ServiceDiscovery {
* @param hostname
* @param responseType Specifies the DNS response type for the virtual node.
* The default is `DnsResponseType.LOAD_BALANCER`.
* @param ipPreference No IP preference is applied to the Virtual Node.
*/
public static dns(hostname: string, responseType?: DnsResponseType): ServiceDiscovery {
return new DnsServiceDiscovery(hostname, responseType);
public static dns(hostname: string, responseType?: DnsResponseType, ipPreference?: IpPreference): ServiceDiscovery {
return new DnsServiceDiscovery(hostname, responseType, ipPreference);
}

/**
Expand All @@ -61,9 +108,10 @@ export abstract class ServiceDiscovery {
* filter instances by any custom attribute that you specified when you
* registered the instance. Only instances that match all of the specified
* key/value pairs will be returned.
* @param ipPreference No IP preference is applied to the Virtual Node.
*/
public static cloudMap(service: cloudmap.IService, instanceAttributes?: {[key: string]: string}): ServiceDiscovery {
return new CloudMapServiceDiscovery(service, instanceAttributes);
public static cloudMap(service: cloudmap.IService, instanceAttributes?: {[key: string]: string}, ipPreference?: IpPreference): ServiceDiscovery {
return new CloudMapServiceDiscovery(service, instanceAttributes, ipPreference);
}

/**
Expand All @@ -75,18 +123,21 @@ export abstract class ServiceDiscovery {
class DnsServiceDiscovery extends ServiceDiscovery {
private readonly hostname: string;
private readonly responseType?: DnsResponseType;
private readonly ipPreference?: IpPreference;

constructor(hostname: string, responseType?: DnsResponseType) {
constructor(hostname: string, responseType?: DnsResponseType, ipPreference?: IpPreference) {
super();
this.hostname = hostname;
this.responseType = responseType;
this.ipPreference = ipPreference;
}

public bind(_scope: Construct): ServiceDiscoveryConfig {
return {
dns: {
hostname: this.hostname,
responseType: this.responseType,
ipPreference: this.ipPreference,
},
};
}
Expand All @@ -95,11 +146,13 @@ class DnsServiceDiscovery extends ServiceDiscovery {
class CloudMapServiceDiscovery extends ServiceDiscovery {
private readonly service: cloudmap.IService;
private readonly instanceAttributes?: {[key: string]: string};
private readonly ipPreference?: IpPreference;

constructor(service: cloudmap.IService, instanceAttributes?: {[key: string]: string}) {
constructor(service: cloudmap.IService, instanceAttributes?: {[key: string]: string}, ipPreference?: IpPreference) {
super();
this.service = service;
this.instanceAttributes = instanceAttributes;
this.ipPreference = ipPreference;
}

public bind(_scope: Construct): ServiceDiscoveryConfig {
Expand All @@ -108,6 +161,7 @@ class CloudMapServiceDiscovery extends ServiceDiscovery {
namespaceName: this.service.namespace.namespaceName,
serviceName: this.service.serviceName,
attributes: renderAttributes(this.instanceAttributes),
ipPreference: this.ipPreference,
},
};
}
Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-appmesh/test/integ.mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const namespace = new cloudmap.PrivateDnsNamespace(stack, 'test-namespace', {
});

const mesh = new appmesh.Mesh(stack, 'mesh');
new appmesh.Mesh(stack, 'mesh-with-preference', {
serviceDiscovery: {
ipPreference: appmesh.IpPreference.IPV4_ONLY,
},
});
const router = mesh.addVirtualRouter('router', {
listeners: [
appmesh.VirtualRouterListener.http(),
Expand All @@ -29,7 +34,7 @@ const virtualService = new appmesh.VirtualService(stack, 'service', {
});

const node = mesh.addVirtualNode('node', {
serviceDiscovery: appmesh.ServiceDiscovery.dns(`node1.${namespace.namespaceName}`),
serviceDiscovery: appmesh.ServiceDiscovery.dns(`node1.${namespace.namespaceName}`, undefined, appmesh.IpPreference.IPV4_ONLY),
listeners: [appmesh.VirtualNodeListener.http({
healthCheck: appmesh.HealthCheck.http({
healthyThreshold: 3,
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"17.0.0"}
{"version":"20.0.0"}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "18.0.0",
"version": "20.0.0",
"testCases": {
"aws-appmesh/test/integ.mesh": {
"integ.mesh": {
"stacks": [
"mesh-stack"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "17.0.0",
"version": "20.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
Expand Down Expand Up @@ -291,6 +291,12 @@
"data": "meshgateway1gateway1routegrpc2FAC1FF36"
}
],
"/mesh-stack/mesh-with-preference/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "meshwithpreferenceCC9682C9"
}
],
"/mesh-stack/service/Resource": [
{
"type": "aws:cdk:logicalId",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "20.0.0",
"files": {
"be244c434fce5ce2d030a96121c147910d423314d1807320ddf66a562a53550d": {
"source": {
"path": "mesh-stack.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "be244c434fce5ce2d030a96121c147910d423314d1807320ddf66a562a53550d.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,8 @@
],
"ServiceDiscovery": {
"DNS": {
"Hostname": "node1.domain.local"
"Hostname": "node1.domain.local",
"IpPreference": "IPv4_ONLY"
}
}
},
Expand Down Expand Up @@ -1672,6 +1673,17 @@
"GatewayRouteName": "meshstackmeshgateway1gateway1routegrpc2AE8379FD"
}
},
"meshwithpreferenceCC9682C9": {
"Type": "AWS::AppMesh::Mesh",
"Properties": {
"MeshName": "meshstackmeshwithpreference13C624E1",
"Spec": {
"ServiceDiscovery": {
"IpPreference": "IPv4_ONLY"
}
}
}
},
"service6D174F83": {
"Type": "AWS::AppMesh::VirtualService",
"Properties": {
Expand Down
Loading

0 comments on commit d1c4f38

Please sign in to comment.