Skip to content

Commit

Permalink
Merge branch 'master' into huijbers/dupe-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 27, 2021
2 parents a49fa79 + 126a693 commit 2d0f1dd
Show file tree
Hide file tree
Showing 35 changed files with 2,153 additions and 557 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,35 @@

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.

## [1.87.0](https://github.com/aws/aws-cdk/compare/v1.86.0...v1.87.0) (2021-01-27)


### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES

* **s3-deployment:** User metadata keys of bucket objects will change from `x-amz-meta-x-amz-meta-x-amzn-meta-mykey` to `x-amz-meta-mykey`.
* **core:** users of modern synthesis (`DefaultSynthesizer`,
used by CDK Pipelines) must upgrade their bootstrap stacks. Run `cdk bootstrap`.

### Features

* **aws-codebuild:** add `enableBatchBuilds()` to Project ([#12531](https://github.com/aws/aws-cdk/issues/12531)) ([0568390](https://github.com/aws/aws-cdk/commit/05683907d6ffc9ab12b6744c1b59b0df096789e1))
* **aws-codepipeline-actions:** Add Full Clone support for CodeCommit ([#12558](https://github.com/aws/aws-cdk/issues/12558)) ([d169688](https://github.com/aws/aws-cdk/commit/d169688f35bc78c88c44ff9a7d8fa0dfea71f904)), closes [#12236](https://github.com/aws/aws-cdk/issues/12236)
* **batch:** Compute Resources placement group ([#12203](https://github.com/aws/aws-cdk/issues/12203)) ([fe37174](https://github.com/aws/aws-cdk/commit/fe37174ec29b7d3b60b252df08ceecf1aa057098))
* **eks:** Graduate to stable ([#12640](https://github.com/aws/aws-cdk/issues/12640)) ([b5ba7cd](https://github.com/aws/aws-cdk/commit/b5ba7cdd61714bcfbf2135240790340a77ee1a8b))
* **stepfunctions-tasks:** EcsRunTask now uses taskDefinition family instead of ARN ([#12436](https://github.com/aws/aws-cdk/issues/12436)) ([abde96b](https://github.com/aws/aws-cdk/commit/abde96b046358fc5435545692eba4fd63d503914)), closes [#12080](https://github.com/aws/aws-cdk/issues/12080)
* **stepfunctions-tasks:** support databrew startJobRun task ([#12532](https://github.com/aws/aws-cdk/issues/12532)) ([eacd2f7](https://github.com/aws/aws-cdk/commit/eacd2f7ea67c83d50c839acf29fbe953ae49d987))


### Bug Fixes

* **apigatewayv2:** multiple http integrations are created for each route ([#12528](https://github.com/aws/aws-cdk/issues/12528)) ([855ce59](https://github.com/aws/aws-cdk/commit/855ce59039a577d142d68720e86d81610edffc64)), closes [40aws-cdk/aws-apigatewayv2/lib/http/route.ts#L128](https://github.com/40aws-cdk/aws-apigatewayv2/lib/http/route.ts/issues/L128)
* **core:** modern deployments fail if bootstrap stack is renamed ([#12594](https://github.com/aws/aws-cdk/issues/12594)) ([e5c616f](https://github.com/aws/aws-cdk/commit/e5c616f73eac395492636341f57fb6a716d1ea69)), closes [#11952](https://github.com/aws/aws-cdk/issues/11952) [#11420](https://github.com/aws/aws-cdk/issues/11420) [#9053](https://github.com/aws/aws-cdk/issues/9053)
* **pipelines:** assets broken in Pipelines synthesized from Windows ([#12573](https://github.com/aws/aws-cdk/issues/12573)) ([5c3dce5](https://github.com/aws/aws-cdk/commit/5c3dce56c71083321069a31213aaa5bce40f51d3)), closes [#12540](https://github.com/aws/aws-cdk/issues/12540)
* **pipelines:** can't use CodePipeline variables in Synth environment variables ([#12602](https://github.com/aws/aws-cdk/issues/12602)) ([736b260](https://github.com/aws/aws-cdk/commit/736b260db7f21d89e220591007580f62b22fea3a)), closes [#12061](https://github.com/aws/aws-cdk/issues/12061) [#11178](https://github.com/aws/aws-cdk/issues/11178)
* **pipelines:** unable to publish assets inside VPC ([#12331](https://github.com/aws/aws-cdk/issues/12331)) ([a16f09c](https://github.com/aws/aws-cdk/commit/a16f09c9ea675caf5b1e50a4e1cc288e5afd1237)), closes [#11815](https://github.com/aws/aws-cdk/issues/11815)
* **s3-deployment:** User metadata keys have redundant triple `x-amz` prefix ([#12414](https://github.com/aws/aws-cdk/issues/12414)) ([6716181](https://github.com/aws/aws-cdk/commit/671618152dc585ef0703f6c3501f6ee5a366b4a9)), closes [#8459](https://github.com/aws/aws-cdk/issues/8459)
* **secretsmanager:** fromSecretPartialArn() has incorrect grant policies ([#12665](https://github.com/aws/aws-cdk/issues/12665)) ([560915e](https://github.com/aws/aws-cdk/commit/560915ece87a919f499a64452b919a0b291394ee)), closes [#12411](https://github.com/aws/aws-cdk/issues/12411)

## [1.86.0](https://github.com/aws/aws-cdk/compare/v1.85.0...v1.86.0) (2021-01-21)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class EdgeFunction extends Resource implements lambda.IVersion {
throw new Error('stacks which use EdgeFunctions must have an explicitly set region');
}

const edgeStackId = stackId ?? `edge-lambda-stack-${region}`;
const edgeStackId = stackId ?? `edge-lambda-stack-${this.stack.node.addr}`;
let edgeStack = stage.node.tryFindChild(edgeStackId) as Stack;
if (!edgeStack) {
edgeStack = new Stack(stage, edgeStackId, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ function defaultEdgeFunctionProps(stackId?: string) {
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
runtime: lambda.Runtime.NODEJS_12_X,
stackId: stackId ?? 'edge-lambda-stack-testregion',
stackId: stackId,
};
}

function getFnStack(region: string = 'testregion'): cdk.Stack {
return app.node.findChild(`edge-lambda-stack-${region}`) as cdk.Stack;
function getFnStack(): cdk.Stack {
return app.node.findChild(`edge-lambda-stack-${stack.node.addr}`) as cdk.Stack;
}
33 changes: 24 additions & 9 deletions packages/@aws-cdk/aws-ec2/lib/bastion-host.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IPrincipal, IRole, PolicyStatement } from '@aws-cdk/aws-iam';
import { CfnOutput, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { AmazonLinuxGeneration, InstanceClass, InstanceSize, InstanceType } from '.';
import { AmazonLinuxGeneration, InstanceArchitecture, InstanceClass, InstanceSize, InstanceType } from '.';
import { Connections } from './connections';
import { IInstance, Instance } from './instance';
import { IMachineImage, MachineImage } from './machine-image';
import { AmazonLinuxCpuType, IMachineImage, MachineImage } from './machine-image';
import { IPeer } from './peer';
import { Port } from './port';
import { ISecurityGroup } from './security-group';
Expand Down Expand Up @@ -60,10 +60,10 @@ export interface BastionHostLinuxProps {
readonly instanceType?: InstanceType;

/**
* The machine image to use
* The machine image to use, assumed to have SSM Agent preinstalled.
*
* @default - An Amazon Linux 2 image which is kept up-to-date automatically (the instance
* may be replaced on every deployment).
* may be replaced on every deployment) and already has SSM Agent installed.
*/
readonly machineImage?: IMachineImage;

Expand Down Expand Up @@ -146,14 +146,17 @@ export class BastionHostLinux extends Resource implements IInstance {
constructor(scope: Construct, id: string, props: BastionHostLinuxProps) {
super(scope, id);
this.stack = Stack.of(scope);

const instanceType = props.instanceType ?? InstanceType.of(InstanceClass.T3, InstanceSize.NANO);
this.instance = new Instance(this, 'Resource', {
vpc: props.vpc,
availabilityZone: props.availabilityZone,
securityGroup: props.securityGroup,
instanceName: props.instanceName ?? 'BastionHost',
instanceType: props.instanceType ?? InstanceType.of(InstanceClass.T3, InstanceSize.NANO),
machineImage: props.machineImage ?? MachineImage.latestAmazonLinux({ generation: AmazonLinuxGeneration.AMAZON_LINUX_2 }),
instanceType,
machineImage: props.machineImage ?? MachineImage.latestAmazonLinux({
generation: AmazonLinuxGeneration.AMAZON_LINUX_2,
cpuType: this.toAmazonLinuxCpuType(instanceType.architecture),
}),
vpcSubnets: props.subnetSelection ?? {},
blockDevices: props.blockDevices ?? undefined,
});
Expand All @@ -165,8 +168,6 @@ export class BastionHostLinux extends Resource implements IInstance {
],
resources: ['*'],
}));
this.instance.addUserData('yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm');

this.connections = this.instance.connections;
this.role = this.instance.role;
this.grantPrincipal = this.instance.role;
Expand All @@ -183,6 +184,20 @@ export class BastionHostLinux extends Resource implements IInstance {
});
}

/**
* Returns the AmazonLinuxCpuType corresponding to the given instance architecture
* @param architecture the instance architecture value to convert
*/
private toAmazonLinuxCpuType(architecture: InstanceArchitecture): AmazonLinuxCpuType {
if (architecture === InstanceArchitecture.ARM_64) {
return AmazonLinuxCpuType.ARM_64;
} else if (architecture === InstanceArchitecture.X86_64) {
return AmazonLinuxCpuType.X86_64;
}

throw new Error(`Unsupported instance architecture '${architecture}'`);
}

/**
* Allow SSH access from the given peer or peers
*
Expand Down
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/instance-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,21 @@ export enum InstanceClass {
INF1 = 'inf1'
}

/**
* Identifies an instance's CPU architecture
*/
export enum InstanceArchitecture {
/**
* ARM64 architecture
*/
ARM_64 = 'arm64',

/**
* x86-64 architecture
*/
X86_64 = 'x86_64',
}

/**
* What size of instance to use
*/
Expand Down Expand Up @@ -597,4 +612,26 @@ export class InstanceType {
public toString(): string {
return this.instanceTypeIdentifier;
}

/**
* The instance's CPU architecture
*/
public get architecture(): InstanceArchitecture {
// capture the family, generation, capabilities, and size portions of the instance type id
const instanceTypeComponents = this.instanceTypeIdentifier.match(/^([a-z]+)(\d{1,2})([a-z]*)\.([a-z0-9]+)$/);
if (instanceTypeComponents == null) {
throw new Error('Malformed instance type identifier');
}

const family = instanceTypeComponents[1];
const capabilities = instanceTypeComponents[3];

// Instance family `a` are first-gen Graviton instances
// Capability `g` indicates the instance is Graviton2 powered
if (family === 'a' || capabilities.includes('g')) {
return InstanceArchitecture.ARM_64;
}

return InstanceArchitecture.X86_64;
}
}
41 changes: 40 additions & 1 deletion packages/@aws-cdk/aws-ec2/test/bastion-host.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, haveResource } from '@aws-cdk/assert';
import { Stack } from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import { BastionHostLinux, BlockDeviceVolume, SubnetType, Vpc } from '../lib';
import { BastionHostLinux, BlockDeviceVolume, InstanceClass, InstanceSize, InstanceType, SubnetType, Vpc } from '../lib';

nodeunitShim({
'default instance is created in basic'(test: Test) {
Expand Down Expand Up @@ -83,6 +83,45 @@ nodeunitShim({
],
}));

test.done();
},
'x86-64 instances use x86-64 image by default'(test: Test) {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');

// WHEN
new BastionHostLinux(stack, 'Bastion', {
vpc,
});

// THEN
expect(stack).to(haveResource('AWS::EC2::Instance', {
ImageId: {
Ref: 'SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmx8664gp2C96584B6F00A464EAD1953AFF4B05118Parameter',
},
}));

test.done();
},
'arm instances use arm image by default'(test: Test) {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');

// WHEN
new BastionHostLinux(stack, 'Bastion', {
vpc,
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.NANO),
});

// THEN
expect(stack).to(haveResource('AWS::EC2::Instance', {
ImageId: {
Ref: 'SsmParameterValueawsserviceamiamazonlinuxlatestamzn2amihvmarm64gp2C96584B6F00A464EAD1953AFF4B05118Parameter',
},
}));

test.done();
},
});
51 changes: 50 additions & 1 deletion packages/@aws-cdk/aws-ec2/test/instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Stack } from '@aws-cdk/core';
import { nodeunitShim, Test } from 'nodeunit-shim';
import {
AmazonLinuxImage, BlockDeviceVolume, CloudFormationInit,
EbsDeviceVolumeType, InitCommand, Instance, InstanceClass, InstanceSize, InstanceType, UserData, Vpc,
EbsDeviceVolumeType, InitCommand, Instance, InstanceArchitecture, InstanceClass, InstanceSize, InstanceType, UserData, Vpc,
} from '../lib';


Expand Down Expand Up @@ -107,7 +107,56 @@ nodeunitShim({

test.done();
},
'instance architecture is correctly discerned for arm instances'(test: Test) {
// GIVEN
const sampleInstanceClasses = [
'a1', 't4g', 'c6g', 'c6gd', 'c6gn', 'm6g', 'm6gd', 'r6g', 'r6gd', // current Graviton-based instance classes
'a13', 't11g', 'y10ng', 'z11ngd', // theoretical future Graviton-based instance classes
];

for (const instanceClass of sampleInstanceClasses) {
// WHEN
const instanceType = InstanceType.of(instanceClass as InstanceClass, InstanceSize.XLARGE18);

// THEN
expect(instanceType.architecture).toBe(InstanceArchitecture.ARM_64);
}

test.done();
},
'instance architecture is correctly discerned for x86-64 instance'(test: Test) {
// GIVEN
const sampleInstanceClasses = ['c5', 'm5ad', 'r5n', 'm6', 't3a']; // A sample of x86-64 instance classes

for (const instanceClass of sampleInstanceClasses) {
// WHEN
const instanceType = InstanceType.of(instanceClass as InstanceClass, InstanceSize.XLARGE18);

// THEN
expect(instanceType.architecture).toBe(InstanceArchitecture.X86_64);
}

test.done();
},
'instance architecture throws an error when instance type is invalid'(test: Test) {
// GIVEN
const malformedInstanceTypes = ['t4', 't4g.nano.', 't4gnano', ''];

for (const malformedInstanceType of malformedInstanceTypes) {
// WHEN
const instanceType = new InstanceType(malformedInstanceType);

// THEN
try {
instanceType.architecture;
expect(true).toBe(false); // The line above should have thrown an error
} catch (err) {
expect(err.message).toBe('Malformed instance type identifier');
}
}

test.done();
},
blockDeviceMappings: {
'can set blockDeviceMappings'(test: Test) {
// WHEN
Expand Down
Loading

0 comments on commit 2d0f1dd

Please sign in to comment.