Skip to content

Commit a2a036e

Browse files
authored
Merge branch 'master' into nija-at/cognito-userpool-idp
2 parents f2bba19 + 1199e33 commit a2a036e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1426
-243
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# VSCode extension
2-
.vscode/
2+
3+
# Store launch config in repo but not settings
4+
.vscode/settings.json
35
/.favorites.json
46

57
# TypeScript incremental build states

.vscode/launch.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
// Has convenient settings for attaching to a NodeJS process for debugging purposes
9+
// that are NOT the default and otherwise every developers has to configure for
10+
// themselves again and again.
11+
"type": "node",
12+
"request": "attach",
13+
"name": "Attach to NodeJS",
14+
// If we don't do this, every step-into into an async function call will go into
15+
// NodeJS internals which are hard to step out of.
16+
"skipFiles": [
17+
"<node_internals>/**"
18+
],
19+
// Saves some button-pressing latency on attaching
20+
"stopOnEntry": false
21+
}
22+
]
23+
}

CHANGELOG.md

+7
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.42.1](https://github.com/aws/aws-cdk/compare/v1.42.0...v1.42.1) (2020-06-01)
6+
7+
8+
### Bug Fixes
9+
10+
* **lambda:** `SingletonFunction.grantInvoke()` API fails with error 'No child with id' ([#8296](https://github.com/aws/aws-cdk/issues/8296)) ([b4e264c](https://github.com/aws/aws-cdk/commit/b4e264c024bc58053412be1343bed6458628f7cb)), closes [#8240](https://github.com/aws/aws-cdk/issues/8240)
11+
512
## [1.42.0](https://github.com/aws/aws-cdk/compare/v1.41.0...v1.42.0) (2020-05-27)
613

714

CONTRIBUTING.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ and let us know if it's not up-to-date (even better, submit a PR with your corr
4343
- [Troubleshooting](#troubleshooting)
4444
- [Debugging](#debugging)
4545
- [Connecting the VS Code Debugger](#connecting-the-vs-code-debugger)
46+
- [Run a CDK unit test in the debugger](#run-a-cdk-unit-test-in-the-debugger)
4647
- [Related Repositories](#related-repositories)
4748

4849
## Getting Started
@@ -234,7 +235,7 @@ BREAKING CHANGE: Description of what broke and how to achieve this behavior now
234235
### Step 5: Pull Request
235236

236237
* Push to a GitHub fork or to a branch (naming convention: `<user>/<feature-bug-name>`)
237-
* Submit a Pull Requests on GitHub and assign the PR for a review to the "awslabs/aws-cdk" team.
238+
* Submit a Pull Request on GitHub. A reviewer will later be assigned by the maintainers.
238239
* Please follow the PR checklist written below. We trust our contributors to self-check, and this helps that process!
239240
* Discuss review comments and iterate until you get at least one “Approve”. When iterating, push new commits to the
240241
same branch. Usually all these are going to be squashed when you merge to master. The commit messages should be hints
@@ -327,7 +328,7 @@ All packages in the repo use a standard base configuration found at [eslintrc.js
327328
This can be customized for any package by modifying the `.eslintrc` file found at its root.
328329

329330
If you're using the VS Code and would like to see eslint violations on it, install the [eslint
330-
extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
331+
extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).
331332

332333
#### pkglint
333334

@@ -910,6 +911,24 @@ To debug your CDK application along with the CDK repository,
910911
6. The debug view, should now have a launch configuration called 'Debug hello-cdk' and launching that will start the debugger.
911912
7. Any time you modify the CDK app or any of the CDK modules, they need to be re-built and depending on the change the `link-all.sh` script from step#2, may need to be re-run. Only then, would VS code recognize the change and potentially the breakpoint.
912913

914+
### Run a CDK unit test in the debugger
915+
916+
If you want to run the VSCode debugger on unit tests of the CDK project
917+
itself, do the following:
918+
919+
1. Set a breakpoint inside your unit test.
920+
2. In your terminal, depending on the type of test, run either:
921+
922+
```
923+
# (For tests names test.xxx.ts)
924+
$ node --inspect-brk /path/to/aws-cdk/node_modules/.bin/nodeunit -t 'TESTNAME'
925+
926+
# (For tests names xxxx.test.ts)
927+
$ node --inspect-brk /path/to/aws-cdk/node_modules/.bin/jest -i -t 'TESTNAME'
928+
```
929+
930+
3. On the `Run` pane of VSCode, select the run configuration **Attach to NodeJS** and click the button.
931+
913932
## Related Repositories
914933

915934
* [Samples](https://github.com/aws-samples/aws-cdk-examples): includes sample code in multiple languages

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"tools/*"
1111
],
1212
"rejectCycles": "true",
13-
"version": "1.42.0"
13+
"version": "1.42.1"
1414
}

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

+125-63
Original file line numberDiff line numberDiff line change
@@ -13,101 +13,82 @@
1313
---
1414
<!--END STABILITY BANNER-->
1515

16-
Add a CloudTrail construct - for ease of setting up CloudTrail logging in your account
16+
## Trail
1717

18-
Example usage:
18+
AWS CloudTrail enables governance, compliance, and operational and risk auditing of your AWS account. Actions taken by
19+
a user, role, or an AWS service are recorded as events in CloudTrail. Learn more at the [CloudTrail
20+
documentation](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html).
1921

20-
```ts
21-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
22+
The `Trail` construct enables ongoing delivery of events as log files to an Amazon S3 bucket. Learn more about [Creating
23+
a Trail for Your AWS Account](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-create-and-update-a-trail.html).
24+
The following code creates a simple CloudTrail for your account -
2225

26+
```ts
2327
const trail = new cloudtrail.Trail(this, 'CloudTrail');
2428
```
2529

26-
You can instantiate the CloudTrail construct with no arguments - this will by default:
30+
By default, this will create a new S3 Bucket that CloudTrail will write to, and choose a few other reasonable defaults
31+
such as turning on multi-region and global service events.
32+
The defaults for each property and how to override them are all documented on the `TrailProps` interface.
2733

28-
* Create a new S3 Bucket and associated Policy that allows CloudTrail to write to it
29-
* Create a CloudTrail with the following configuration:
30-
* Logging Enabled
31-
* Log file validation enabled
32-
* Multi Region set to true
33-
* Global Service Events set to true
34-
* The created S3 bucket
35-
* CloudWatch Logging Disabled
36-
* No SNS configuartion
37-
* No tags
38-
* No fixed name
34+
## Log File Validation
3935

40-
You can override any of these properties using the `CloudTrailProps` configuraiton object.
36+
In order to validate that the CloudTrail log file was not modified after CloudTrail delivered it, CloudTrail provides a
37+
digital signature for each file. Learn more at [Validating CloudTrail Log File
38+
Integrity](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-log-file-validation-intro.html).
4139

42-
For example, to log to CloudWatch Logs
40+
This is enabled on the `Trail` construct by default, but can be turned off by setting `enableFileValidation` to `false`.
4341

4442
```ts
45-
46-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
47-
4843
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
49-
sendToCloudWatchLogs: true
44+
enableFileValidation: false,
5045
});
5146
```
5247

53-
This creates the same setup as above - but also logs events to a created CloudWatch Log stream.
54-
By default, the created log group has a retention period of 365 Days, but this is also configurable
55-
via the `cloudWatchLogsRetention` property. If you would like to specify the log group explicitly,
56-
use the `cloudwatchLogGroup` property.
48+
## Notifications
5749

58-
For using CloudTrail event selector to log specific S3 events,
59-
you can use the `CloudTrailProps` configuration object.
60-
Example:
50+
Amazon SNS notifications can be configured upon new log files containing Trail events are delivered to S3.
51+
Learn more at [Configuring Amazon SNS Notifications for
52+
CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/configure-sns-notifications-for-cloudtrail.html).
53+
The following code configures an SNS topic to be notified -
6154

6255
```ts
63-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
56+
const topic = new sns.Topic(this, 'TrailTopic');
57+
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
58+
snsTopic: topic,
59+
});
60+
```
6461

65-
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
62+
## Service Integrations
6663

67-
// Adds an event selector to the bucket magic-bucket.
68-
// By default, this includes management events and all operations (Read + Write)
69-
trail.logAllS3DataEvents();
64+
Besides sending trail events to S3, they can also be configured to notify other AWS services -
7065

71-
// Adds an event selector to the bucket foo
72-
trail.addS3EventSelector([{
73-
bucket: fooBucket // 'fooBucket' is of type s3.IBucket
74-
}]);
75-
```
66+
### Amazon CloudWatch Logs
7667

77-
For using CloudTrail event selector to log events about Lambda
78-
functions, you can use `addLambdaEventSelector`.
68+
CloudTrail events can be delivered to a CloudWatch Logs LogGroup. By default, a new LogGroup is created with a
69+
default retention setting. The following code enables sending CloudWatch logs but specifies a particular retention
70+
period for the created Log Group.
7971

8072
```ts
81-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
82-
import * as lambda from '@aws-cdk/aws-lambda';
83-
84-
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
85-
const lambdaFunction = new lambda.Function(stack, 'AnAmazingFunction', {
86-
runtime: lambda.Runtime.NODEJS_10_X,
87-
handler: "hello.handler",
88-
code: lambda.Code.fromAsset("lambda"),
73+
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
74+
sendToCloudWatchLogs: true,
75+
cloudWatchLogsRetention: logs.RetentionDays.FOUR_MONTHS,
8976
});
77+
```
9078

91-
// Add an event selector to log data events for all functions in the account.
92-
trail.logAllLambdaDataEvents();
79+
If you would like to use a specific log group instead, this can be configured via `cloudwatchLogGroup`.
9380

94-
// Add an event selector to log data events for the provided Lambda functions.
95-
trail.addLambdaEventSelector([lambdaFunction.functionArn]);
96-
```
81+
### Amazon EventBridge
9782

98-
Using the `Trail.onEvent()` API, an EventBridge rule can be created that gets triggered for
99-
every event logged in CloudTrail.
100-
To only use the events that are of interest, either from a particular service, specific account or
101-
time range, they can be filtered down using the APIs available in `aws-events`. The following code
102-
filters events for S3 from a specific AWS account and triggers a lambda function. See [Events delivered via
83+
Amazon EventBridge rules can be configured to be triggered when CloudTrail events occur using the `Trail.onEvent()` API.
84+
Using APIs available in `aws-events`, these events can be filtered to match to those that are of interest, either from
85+
a specific service, account or time range. See [Events delivered via
10386
CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#events-for-services-not-listed)
10487
to learn more about the event structure for events from CloudTrail.
10588

106-
```ts
107-
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
108-
import * as eventTargets from '@aws-cdk/aws-events-targets';
109-
import * as lambda from '@aws-cdk/aws-lambda';
89+
The following code filters events for S3 from a specific AWS account and triggers a lambda function.
11090

91+
```ts
11192
const myFunctionHandler = new lambda.Function(this, 'MyFunction', {
11293
code: lambda.Code.fromAsset('resource/myfunction');
11394
runtime: lambda.Runtime.NODEJS_12_X,
@@ -123,3 +104,84 @@ eventRule.addEventPattern({
123104
source: 'aws.s3',
124105
});
125106
```
107+
108+
## Multi-Region & Global Service Events
109+
110+
By default, a `Trail` is configured to deliver log files from multiple regions to a single S3 bucket for a given
111+
account. This creates shadow trails (replication of the trails) in all of the other regions. Learn more about [How
112+
CloudTrail Behaves Regionally](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-regional-and-global-services)
113+
and about the [`IsMultiRegion`
114+
property](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudtrail-trail.html#cfn-cloudtrail-trail-ismultiregiontrail).
115+
116+
For most services, events are recorded in the region where the action occurred. For global services such as AWS IAM,
117+
AWS STS, Amazon CloudFront, Route 53, etc., events are delivered to any trail that includes global services. Learn more
118+
[About Global Service Events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-global-service-events).
119+
120+
Events for global services are turned on by default for `Trail` constructs in the CDK.
121+
122+
The following code disables multi-region trail delivery and trail delivery for global services for a specific `Trail` -
123+
124+
```ts
125+
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
126+
// ...
127+
isMultiRegionTrail: false,
128+
includeGlobalServiceEvents: false,
129+
});
130+
```
131+
132+
## Events Types
133+
134+
**Management events** provide information about management operations that are performed on resources in your AWS
135+
account. These are also known as control plane operations. Learn more about [Management
136+
Events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-events).
137+
138+
By default, a `Trail` logs all management events. However, they can be configured to either be turned off, or to only
139+
log 'Read' or 'Write' events.
140+
141+
The following code configures the `Trail` to only track management events that are of type 'Read'.
142+
143+
```ts
144+
const trail = new cloudtrail.Trail(this, 'CloudTrail', {
145+
// ...
146+
managementEvents: ReadWriteType.READ_ONLY,
147+
});
148+
```
149+
150+
**Data events** provide information about the resource operations performed on or in a resource. These are also known
151+
as data plane operations. Learn more about [Data
152+
Events](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-concepts.html#cloudtrail-concepts-events).
153+
By default, no data events are logged for a `Trail`.
154+
155+
AWS CloudTrail supports data event logging for Amazon S3 objects and AWS Lambda functions.
156+
157+
The `logAllS3DataEvents()` API configures the trail to log all S3 data events while the `addS3EventSelector()` API can
158+
be used to configure logging of S3 data events for specific buckets and specific object prefix. The following code
159+
configures logging of S3 data events for `fooBucket` and with object prefix `bar/`.
160+
161+
```ts
162+
import * as cloudtrail from '@aws-cdk/aws-cloudtrail';
163+
164+
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
165+
166+
// Adds an event selector to the bucket foo
167+
trail.addS3EventSelector([{
168+
bucket: fooBucket, // 'fooBucket' is of type s3.IBucket
169+
objectPrefix: 'bar/',
170+
}]);
171+
```
172+
173+
Similarly, the `logAllLambdaDataEvents()` configures the trail to log all Lambda data events while the
174+
`addLambdaEventSelector()` API can be used to configure logging for specific Lambda functions. The following code
175+
configures logging of Lambda data events for a specific Function.
176+
177+
```ts
178+
const trail = new cloudtrail.Trail(this, 'MyAmazingCloudTrail');
179+
const amazingFunction = new lambda.Function(stack, 'AnAmazingFunction', {
180+
runtime: lambda.Runtime.NODEJS_10_X,
181+
handler: "hello.handler",
182+
code: lambda.Code.fromAsset("lambda"),
183+
});
184+
185+
// Add an event selector to log data events for the provided Lambda functions.
186+
trail.addLambdaEventSelector([ lambdaFunction ]);
187+
```

packages/@aws-cdk/aws-cloudtrail/lib/cloudtrail.ts

+18-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface TrailProps {
4141
*
4242
* @param managementEvents the management configuration type to log
4343
*
44-
* @default - Management events will not be logged.
44+
* @default ReadWriteType.ALL
4545
*/
4646
readonly managementEvents?: ReadWriteType;
4747

@@ -131,7 +131,12 @@ export enum ReadWriteType {
131131
/**
132132
* All events
133133
*/
134-
ALL = 'All'
134+
ALL = 'All',
135+
136+
/**
137+
* No events
138+
*/
139+
NONE = 'None',
135140
}
136141

137142
/**
@@ -235,10 +240,17 @@ export class Trail extends Resource {
235240
}
236241

237242
if (props.managementEvents) {
238-
const managementEvent = {
239-
includeManagementEvents: true,
240-
readWriteType: props.managementEvents,
241-
};
243+
let managementEvent;
244+
if (props.managementEvents === ReadWriteType.NONE) {
245+
managementEvent = {
246+
includeManagementEvents: false,
247+
};
248+
} else {
249+
managementEvent = {
250+
includeManagementEvents: true,
251+
readWriteType: props.managementEvents,
252+
};
253+
}
242254
this.eventSelectors.push(managementEvent);
243255
}
244256

0 commit comments

Comments
 (0)