Skip to content

Commit

Permalink
Merge branch 'master' into lambda-python-layers
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 12, 2020
2 parents d4da14c + e90a0a9 commit a82411d
Show file tree
Hide file tree
Showing 47 changed files with 1,117 additions and 299 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ yarn-error.log
# Parcel default cache directory
.parcel-cache

# VSCode history plugin
.vscode/.history/

# Cloud9
.c9
6 changes: 6 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
github:
prebuilds:
pullRequestsFromForks: true
addComment: true

image: jsii/superchain

tasks:
- init: yarn build --skip-test --no-bail --skip-prereqs --skip-compat

Expand Down
3 changes: 3 additions & 0 deletions buildspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ phases:
- /bin/bash ./fetch-dotnet-snk.sh
build:
commands:
# we bump here so that our master version won't be identical to the latest published version during tests.
# otherwise this causes problems with verdaccio mirroring.
- '[ ${GIT_BRANCH} = ${REGRESSION_TESTS_BRANCH} ] && /bin/bash ./bump-candidate.sh'
- /bin/bash ./scripts/align-version.sh
- /bin/bash ./build.sh
post_build:
Expand Down
23 changes: 23 additions & 0 deletions bump-candidate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# --------------------------------------------------------------------------------------------------
#
# This script is intended to be used in our master pipeline as a way of incrementing the version number
# so that it doesnt colide with any published version. This is needed because our integration tests launch
# a verdaccio instance that serves local tarballs, and if those tarballs have the same version as
# already published modules, it messes things up.
#
# It does so by using a pre-release rc tag, making it so that locally packed versions will always be
# suffixed with '-rc', distinguishing it from publisehd modules.
#
# If you need to run integration tests locally against the distribution tarballs, you should run this
# script locally as well before building and packing the repository.
#
# This script only increments the version number in the version files, it does not generate a changelog.
#
# --------------------------------------------------------------------------------------------------
set -euo pipefail
version=${1:-minor}

echo "Starting candidate ${version} version bump"

npx standard-version --release-as ${version} --prerelease=rc --skip.commit --skip.changelog
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,11 @@ const integration = new apigw.Integration({
});
```
The uri for the private integration, in the case of a VpcLink, will be set to the DNS name of
the VPC Link's NLB. If the VPC Link has multiple NLBs or the VPC Link is imported or the DNS
name cannot be determined for any other reason, the user is expected to specify the `uri`
property.
Any existing `VpcLink` resource can be imported into the CDK app via the `VpcLink.fromVpcLinkId()`.
```ts
Expand Down
33 changes: 29 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/integration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as iam from '@aws-cdk/aws-iam';
import { Lazy } from '@aws-cdk/core';
import { Method } from './method';
import { IVpcLink } from './vpc-link';
import { IVpcLink, VpcLink } from './vpc-link';

export interface IntegrationOptions {
/**
Expand Down Expand Up @@ -90,7 +91,7 @@ export interface IntegrationOptions {

/**
* The type of network connection to the integration endpoint.
* @default ConnectionType.Internet
* @default - ConnectionType.VPC_LINK if `vpcLink` property is configured; ConnectionType.Internet otherwise.
*/
readonly connectionType?: ConnectionType;

Expand Down Expand Up @@ -199,10 +200,34 @@ export class Integration {
* being integrated, access the REST API object, method ARNs, etc.
*/
public bind(_method: Method): IntegrationConfig {
let uri = this.props.uri;
const options = this.props.options;

if (options?.connectionType === ConnectionType.VPC_LINK && uri === undefined) {
uri = Lazy.stringValue({
// needs to be a lazy since the targets can be added to the VpcLink construct after initialization.
produce: () => {
const vpcLink = options.vpcLink;
if (vpcLink instanceof VpcLink) {
const targets = vpcLink._targetDnsNames;
if (targets.length > 1) {
throw new Error("'uri' is required when there are more than one NLBs in the VPC Link");
} else {
return `http://${targets[0]}`;
}
} else {
throw new Error("'uri' is required when the 'connectionType' is VPC_LINK");
}
},
});
}
return {
options: this.props.options,
options: {
...options,
connectionType: options?.vpcLink ? ConnectionType.VPC_LINK : options?.connectionType,
},
type: this.props.type,
uri: this.props.uri,
uri,
integrationHttpMethod: this.props.integrationHttpMethod,
};
}
Expand Down
16 changes: 12 additions & 4 deletions packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class VpcLink extends Resource implements IVpcLink {
*/
public readonly vpcLinkId: string;

private readonly targets = new Array<elbv2.INetworkLoadBalancer>();
private readonly _targets = new Array<elbv2.INetworkLoadBalancer>();

constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
super(scope, id, {
Expand All @@ -83,17 +83,25 @@ export class VpcLink extends Resource implements IVpcLink {
}

public addTargets(...targets: elbv2.INetworkLoadBalancer[]) {
this.targets.push(...targets);
this._targets.push(...targets);
}

/**
* Return the list of DNS names from the target NLBs.
* @internal
* */
public get _targetDnsNames(): string[] {
return this._targets.map(t => t.loadBalancerDnsName);
}

protected validate(): string[] {
if (this.targets.length === 0) {
if (this._targets.length === 0) {
return ['No targets added to vpc link'];
}
return [];
}

private renderTargets() {
return this.targets.map(nlb => nlb.loadBalancerArn);
return this._targets.map(nlb => nlb.loadBalancerArn);
}
}
140 changes: 140 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.integration.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ABSENT, expect, haveResourceLike } from '@aws-cdk/assert';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
import * as iam from '@aws-cdk/aws-iam';
Expand Down Expand Up @@ -33,6 +34,89 @@ export = {
test.done();
},

'uri is self determined from the NLB'(test: Test) {
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', { vpc });
const link = new apigw.VpcLink(stack, 'link', {
targets: [nlb],
});
const api = new apigw.RestApi(stack, 'restapi');
const integration = new apigw.Integration({
type: apigw.IntegrationType.HTTP_PROXY,
integrationHttpMethod: 'ANY',
options: {
connectionType: apigw.ConnectionType.VPC_LINK,
vpcLink: link,
},
});
api.root.addMethod('GET', integration);

expect(stack).to(haveResourceLike('AWS::ApiGateway::Method', {
Integration: {
Uri: {
'Fn::Join': [
'',
[
'http://',
{
'Fn::GetAtt': [
'NLB55158F82',
'DNSName',
],
},
],
],
},
},
}));

test.done();
},

'uri must be set for VpcLink with multiple NLBs'(test: Test) {
const app = new cdk.App();
const stack = new cdk.Stack(app);
const vpc = new ec2.Vpc(stack, 'VPC');
const nlb1 = new elbv2.NetworkLoadBalancer(stack, 'NLB1', { vpc });
const nlb2 = new elbv2.NetworkLoadBalancer(stack, 'NLB2', { vpc });
const link = new apigw.VpcLink(stack, 'link', {
targets: [nlb1, nlb2],
});
const api = new apigw.RestApi(stack, 'restapi');
const integration = new apigw.Integration({
type: apigw.IntegrationType.HTTP_PROXY,
integrationHttpMethod: 'ANY',
options: {
connectionType: apigw.ConnectionType.VPC_LINK,
vpcLink: link,
},
});
api.root.addMethod('GET', integration);
test.throws(() => app.synth(), /'uri' is required when there are more than one NLBs in the VPC Link/);

test.done();
},

'uri must be set when using an imported VpcLink'(test: Test) {
const app = new cdk.App();
const stack = new cdk.Stack(app);
const link = apigw.VpcLink.fromVpcLinkId(stack, 'link', 'vpclinkid');
const api = new apigw.RestApi(stack, 'restapi');
const integration = new apigw.Integration({
type: apigw.IntegrationType.HTTP_PROXY,
integrationHttpMethod: 'ANY',
options: {
connectionType: apigw.ConnectionType.VPC_LINK,
vpcLink: link,
},
});
api.root.addMethod('GET', integration);
test.throws(() => app.synth(), /'uri' is required when the 'connectionType' is VPC_LINK/);

test.done();
},

'connectionType of INTERNET and vpcLink are mutually exclusive'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -55,4 +139,60 @@ export = {
}), /cannot set 'vpcLink' where 'connectionType' is INTERNET/);
test.done();
},

'connectionType is ABSENT when vpcLink is not specified'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const api = new apigw.RestApi(stack, 'restapi');

// WHEN
const integration = new apigw.Integration({
type: apigw.IntegrationType.HTTP_PROXY,
integrationHttpMethod: 'ANY',
});
api.root.addMethod('ANY', integration);

// THEN
expect(stack).to(haveResourceLike('AWS::ApiGateway::Method', {
HttpMethod: 'ANY',
Integration: {
ConnectionType: ABSENT,
},
}));

test.done();
},

'connectionType defaults to VPC_LINK if vpcLink is configured'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', {
vpc,
});
const link = new apigw.VpcLink(stack, 'link', {
targets: [nlb],
});
const api = new apigw.RestApi(stack, 'restapi');

// WHEN
const integration = new apigw.Integration({
type: apigw.IntegrationType.HTTP_PROXY,
integrationHttpMethod: 'ANY',
options: {
vpcLink: link,
},
});
api.root.addMethod('ANY', integration);

// THEN
expect(stack).to(haveResourceLike('AWS::ApiGateway::Method', {
HttpMethod: 'ANY',
Integration: {
ConnectionType: 'VPC_LINK',
},
}));

test.done();
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfronthttporiginDistributionOrigin162B02709",
"ViewerProtocolPolicy": "allow-all"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfrontloadbalanceroriginDistributionOrigin1BCC75186",
"ViewerProtocolPolicy": "allow-all"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@
"CacheBehaviors": [
{
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"PathPattern": "/api",
"TargetOriginId": "cloudfrontorigingroupDistributionOriginGroup10B57F1D1",
"ViewerProtocolPolicy": "allow-all"
}
],
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfrontorigingroupDistributionOriginGroup10B57F1D1",
"ViewerProtocolPolicy": "allow-all"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfronts3originoaiDistributionOrigin1516C5A91",
"ViewerProtocolPolicy": "allow-all"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"DistributionConfig": {
"DefaultCacheBehavior": {
"CachePolicyId": "658327ea-f89d-4fab-a63d-7e88639e58f6",
"Compress": true,
"TargetOriginId": "cloudfronts3originDistributionOrigin1741C4E95",
"ViewerProtocolPolicy": "allow-all"
},
Expand Down
9 changes: 6 additions & 3 deletions packages/@aws-cdk/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ for more complex use cases.
### Creating a distribution

CloudFront distributions deliver your content from one or more origins; an origin is the location where you store the original version of your
content. Origins can be created from S3 buckets or a custom origin (HTTP server). Each distribution has a default behavior which applies to all
requests to that distribution, and routes requests to a primary origin. Constructs to define origins are in the `@aws-cdk/aws-cloudfront-origins`
module.
content. Origins can be created from S3 buckets or a custom origin (HTTP server). Constructs to define origins are in the `@aws-cdk/aws-cloudfront-origins` module.

Each distribution has a default behavior which applies to all requests to that distribution, and routes requests to a primary origin.
Additional behaviors may be specified for an origin with a given URL path pattern. Behaviors allow routing with multiple origins,
controlling which HTTP methods to support, whether to require users to use HTTPS, and what query strings or cookies to forward to your origin,
among other settings.

#### From an S3 Bucket

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ export interface AddBehaviorOptions {
* See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compressed-content-cloudfront-file-types
* for file types CloudFront will compress.
*
* @default false
* @default true
*/
readonly compress?: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class CacheBehavior {
allowedMethods: this.props.allowedMethods?.methods,
cachedMethods: this.props.cachedMethods?.methods,
cachePolicyId: (this.props.cachePolicy ?? CachePolicy.CACHING_OPTIMIZED).cachePolicyId,
compress: this.props.compress,
compress: this.props.compress ?? true,
originRequestPolicyId: this.props.originRequestPolicy?.originRequestPolicyId,
smoothStreaming: this.props.smoothStreaming,
viewerProtocolPolicy: this.props.viewerProtocolPolicy ?? ViewerProtocolPolicy.ALLOW_ALL,
Expand Down
Loading

0 comments on commit a82411d

Please sign in to comment.