Skip to content

Commit 2720039

Browse files
authored
Merge branch 'master' into huijbers/permissions-boundary
2 parents 488c4e5 + 2c8a409 commit 2720039

File tree

18 files changed

+278
-31
lines changed

18 files changed

+278
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
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.
44

5+
## [1.87.1](https://github.com/aws/aws-cdk/compare/v1.87.0...v1.87.1) (2021-01-28)
6+
7+
8+
### Bug Fixes
9+
10+
* **apigateway:** stack update fails to replace api key ([38cbe62](https://github.com/aws/aws-cdk/commit/38cbe620859d6efabda95dbdd3185a480ab43894)), closes [#12698](https://github.com/aws/aws-cdk/issues/12698)
11+
512
## [1.87.0](https://github.com/aws/aws-cdk/compare/v1.86.0...v1.87.0) (2021-01-27)
613

714

packages/@aws-cdk/assets/lib/fs/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface CopyOptions {
1010
* A strategy for how to handle symlinks.
1111
*
1212
* @default Never
13+
* @deprecated use `followSymlinks` instead
1314
*/
1415
readonly follow?: FollowMode;
1516

packages/@aws-cdk/aws-ecr-assets/lib/image-asset.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import * as assets from '@aws-cdk/assets';
44
import * as ecr from '@aws-cdk/aws-ecr';
5-
import { Annotations, Construct as CoreConstruct, FeatureFlags, IgnoreMode, Stack, Token } from '@aws-cdk/core';
5+
import {
6+
Annotations, AssetStaging, Construct as CoreConstruct, FeatureFlags, FileFingerprintOptions, IgnoreMode, Stack, SymlinkFollowMode, Token,
7+
} from '@aws-cdk/core';
68
import * as cxapi from '@aws-cdk/cx-api';
79
import { Construct } from 'constructs';
810

911
/**
1012
* Options for DockerImageAsset
1113
*/
12-
export interface DockerImageAssetOptions extends assets.FingerprintOptions {
14+
export interface DockerImageAssetOptions extends assets.FingerprintOptions, FileFingerprintOptions {
1315
/**
1416
* ECR repository name
1517
*
@@ -137,8 +139,9 @@ export class DockerImageAsset extends CoreConstruct implements assets.IAsset {
137139
// deletion of the ECR repository the app used).
138140
extraHash.version = '1.21.0';
139141

140-
const staging = new assets.Staging(this, 'Staging', {
142+
const staging = new AssetStaging(this, 'Staging', {
141143
...props,
144+
follow: props.followSymlinks ?? toSymlinkFollow(props.follow),
142145
exclude,
143146
ignoreMode,
144147
sourcePath: dir,
@@ -181,3 +184,13 @@ function validateBuildArgs(buildArgs?: { [key: string]: string }) {
181184
}
182185
}
183186
}
187+
188+
function toSymlinkFollow(follow?: assets.FollowMode): SymlinkFollowMode | undefined {
189+
switch (follow) {
190+
case undefined: return undefined;
191+
case assets.FollowMode.NEVER: return SymlinkFollowMode.NEVER;
192+
case assets.FollowMode.ALWAYS: return SymlinkFollowMode.ALWAYS;
193+
case assets.FollowMode.BLOCK_EXTERNAL: return SymlinkFollowMode.BLOCK_EXTERNAL;
194+
case assets.FollowMode.EXTERNAL: return SymlinkFollowMode.EXTERNAL;
195+
}
196+
}

packages/@aws-cdk/aws-ecr/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,29 @@ grants an IAM user access to call this API.
5151

5252
```ts
5353
import * as iam from '@aws-cdk/aws-iam';
54+
import * as ecr from '@aws-cdk/aws-ecr';
5455

5556
const user = new iam.User(this, 'User', { ... });
56-
iam.AuthorizationToken.grantRead(user);
57+
ecr.AuthorizationToken.grantRead(user);
5758
```
5859

60+
If you access images in the [Public ECR Gallery](https://gallery.ecr.aws/) as well, it is recommended you authenticate to the regsitry to benefit from
61+
higher rate and bandwidth limits.
62+
63+
> See `Pricing` in https://aws.amazon.com/blogs/aws/amazon-ecr-public-a-new-public-container-registry/ and [Service quotas](https://docs.aws.amazon.com/AmazonECR/latest/public/public-service-quotas.html).
64+
65+
The following code snippet grants an IAM user access to retrieve an authorization token for the public gallery.
66+
67+
```ts
68+
import * as iam from '@aws-cdk/aws-iam';
69+
import * as ecr from '@aws-cdk/aws-ecr';
70+
71+
const user = new iam.User(this, 'User', { ... });
72+
ecr.PublicGalleryAuthorizationToken.grantRead(user);
73+
```
74+
75+
This user can then proceed to login to the registry using one of the [authentication methods](https://docs.aws.amazon.com/AmazonECR/latest/public/public-registries.html#public-registry-auth).
76+
5977
## Automatically clean up repositories
6078

6179
You can set life cycle rules to automatically clean up old images from your

packages/@aws-cdk/aws-ecr/lib/auth-token.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import * as iam from '@aws-cdk/aws-iam';
22

33
/**
4-
* Authorization token to access ECR repositories via Docker CLI.
4+
* Authorization token to access private ECR repositories in the current environment via Docker CLI.
5+
*
6+
* @see https://docs.aws.amazon.com/AmazonECR/latest/userguide/registry_auth.html
57
*/
68
export class AuthorizationToken {
79
/**
@@ -18,3 +20,27 @@ export class AuthorizationToken {
1820
private constructor() {
1921
}
2022
}
23+
24+
/**
25+
* Authorization token to access the global public ECR Gallery via Docker CLI.
26+
*
27+
* @see https://docs.aws.amazon.com/AmazonECR/latest/public/public-registries.html#public-registry-auth
28+
*/
29+
export class PublicGalleryAuthorizationToken {
30+
31+
/**
32+
* Grant access to retrieve an authorization token.
33+
*/
34+
public static grantRead(grantee: iam.IGrantable) {
35+
grantee.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({
36+
actions: ['ecr-public:GetAuthorizationToken', 'sts:GetServiceBearerToken'],
37+
// GetAuthorizationToken only allows '*'. See https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonelasticcontainerregistry.html#amazonelasticcontainerregistry-actions-as-permissions
38+
// GetServiceBearerToken only allows '*'. See https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssecuritytokenservice.html#awssecuritytokenservice-actions-as-permissions
39+
resources: ['*'],
40+
}));
41+
}
42+
43+
private constructor() {
44+
}
45+
46+
}

packages/@aws-cdk/aws-ecr/test/test.auth-token.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { expect, haveResourceLike } from '@aws-cdk/assert';
22
import * as iam from '@aws-cdk/aws-iam';
33
import { Stack } from '@aws-cdk/core';
44
import { Test } from 'nodeunit';
5-
import { AuthorizationToken } from '../lib';
5+
import { AuthorizationToken, PublicGalleryAuthorizationToken } from '../lib';
66

77
export = {
8-
'grant()'(test: Test) {
8+
'AuthorizationToken.grantRead()'(test: Test) {
99
// GIVEN
1010
const stack = new Stack();
1111
const user = new iam.User(stack, 'User');
@@ -28,4 +28,32 @@ export = {
2828

2929
test.done();
3030
},
31+
32+
'PublicGalleryAuthorizationToken.grantRead()'(test: Test) {
33+
// GIVEN
34+
const stack = new Stack();
35+
const user = new iam.User(stack, 'User');
36+
37+
// WHEN
38+
PublicGalleryAuthorizationToken.grantRead(user);
39+
40+
// THEN
41+
expect(stack).to(haveResourceLike('AWS::IAM::Policy', {
42+
PolicyDocument: {
43+
Statement: [
44+
{
45+
Action: [
46+
'ecr-public:GetAuthorizationToken',
47+
'sts:GetServiceBearerToken',
48+
],
49+
Effect: 'Allow',
50+
Resource: '*',
51+
},
52+
],
53+
},
54+
}));
55+
56+
test.done();
57+
},
58+
3159
};

packages/@aws-cdk/aws-ecs-patterns/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,17 @@ const loadBalancedFargateService = new ApplicationLoadBalancedFargateService(sta
427427
},
428428
});
429429
```
430+
431+
### Set PlatformVersion for ScheduledFargateTask
432+
433+
```ts
434+
const scheduledFargateTask = new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
435+
cluster,
436+
scheduledFargateTaskImageOptions: {
437+
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
438+
memoryLimitMiB: 512,
439+
},
440+
schedule: events.Schedule.expression('rate(1 minute)'),
441+
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
442+
});
443+
```

packages/@aws-cdk/aws-ecs-patterns/lib/base/scheduled-task-base.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,20 @@ export abstract class ScheduledTaskBase extends CoreConstruct {
165165
subnetSelection: this.subnetSelection,
166166
});
167167

168-
this.eventRule.addTarget(eventRuleTarget);
168+
this.addTaskAsTarget(eventRuleTarget);
169169

170170
return eventRuleTarget;
171171
}
172172

173+
/**
174+
* Adds task as a target of the scheduled event rule.
175+
*
176+
* @param ecsTaskTarget the EcsTask to add to the event rule
177+
*/
178+
protected addTaskAsTarget(ecsTaskTarget: EcsTask) {
179+
this.eventRule.addTarget(ecsTaskTarget);
180+
}
181+
173182
/**
174183
* Returns the default cluster.
175184
*/

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/scheduled-fargate-task.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { FargateTaskDefinition } from '@aws-cdk/aws-ecs';
1+
import { FargateTaskDefinition, FargatePlatformVersion } from '@aws-cdk/aws-ecs';
2+
import { EcsTask } from '@aws-cdk/aws-events-targets';
23
import { Construct } from 'constructs';
34
import { ScheduledTaskBase, ScheduledTaskBaseProps, ScheduledTaskImageProps } from '../base/scheduled-task-base';
45

@@ -21,6 +22,17 @@ export interface ScheduledFargateTaskProps extends ScheduledTaskBaseProps {
2122
* @default none
2223
*/
2324
readonly scheduledFargateTaskImageOptions?: ScheduledFargateTaskImageOptions;
25+
26+
/**
27+
* The platform version on which to run your service.
28+
*
29+
* If one is not specified, the LATEST platform version is used by default. For more information, see
30+
* [AWS Fargate Platform Versions](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/platform_versions.html)
31+
* in the Amazon Elastic Container Service Developer Guide.
32+
*
33+
* @default Latest
34+
*/
35+
readonly platformVersion?: FargatePlatformVersion;
2436
}
2537

2638
/**
@@ -109,6 +121,15 @@ export class ScheduledFargateTask extends ScheduledTaskBase {
109121
throw new Error('You must specify one of: taskDefinition or image');
110122
}
111123

112-
this.addTaskDefinitionToEventTarget(this.taskDefinition);
124+
// Use the EcsTask as the target of the EventRule
125+
const eventRuleTarget = new EcsTask( {
126+
cluster: this.cluster,
127+
taskDefinition: this.taskDefinition,
128+
taskCount: this.desiredTaskCount,
129+
subnetSelection: this.subnetSelection,
130+
platformVersion: props.platformVersion,
131+
});
132+
133+
this.addTaskAsTarget(eventRuleTarget);
113134
}
114135
}

packages/@aws-cdk/aws-ecs-patterns/test/fargate/test.scheduled-fargate-task.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,60 @@ export = {
294294
],
295295
}));
296296

297+
test.done();
298+
},
299+
'Scheduled Fargate Task - with platformVersion defined'(test: Test) {
300+
// GIVEN
301+
const stack = new cdk.Stack();
302+
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 1 });
303+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
304+
305+
new ScheduledFargateTask(stack, 'ScheduledFargateTask', {
306+
cluster,
307+
scheduledFargateTaskImageOptions: {
308+
image: ecs.ContainerImage.fromRegistry('henk'),
309+
memoryLimitMiB: 512,
310+
},
311+
schedule: events.Schedule.expression('rate(1 minute)'),
312+
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
313+
});
314+
315+
// THEN
316+
expect(stack).to(haveResource('AWS::Events::Rule', {
317+
Targets: [
318+
{
319+
Arn: { 'Fn::GetAtt': ['EcsCluster97242B84', 'Arn'] },
320+
EcsParameters: {
321+
LaunchType: 'FARGATE',
322+
NetworkConfiguration: {
323+
AwsVpcConfiguration: {
324+
AssignPublicIp: 'DISABLED',
325+
SecurityGroups: [
326+
{
327+
'Fn::GetAtt': [
328+
'ScheduledFargateTaskScheduledTaskDefSecurityGroupE075BC19',
329+
'GroupId',
330+
],
331+
},
332+
],
333+
Subnets: [
334+
{
335+
Ref: 'VpcPrivateSubnet1Subnet536B997A',
336+
},
337+
],
338+
},
339+
},
340+
PlatformVersion: '1.4.0',
341+
TaskCount: 1,
342+
TaskDefinitionArn: { Ref: 'ScheduledFargateTaskScheduledTaskDef521FA675' },
343+
},
344+
Id: 'Target0',
345+
Input: '{}',
346+
RoleArn: { 'Fn::GetAtt': ['ScheduledFargateTaskScheduledTaskDefEventsRole6CE19522', 'Arn'] },
347+
},
348+
],
349+
}));
350+
297351
test.done();
298352
},
299353
};

0 commit comments

Comments
 (0)