Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dynamodb): add ability to enable contributor insights on Global Secondary Index #22700

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 15 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,17 @@ changes are only allowed in major versions and those are rare.
To address this need, we have a feature flags pattern/mechanism. It allows us to
introduce new breaking behavior which is disabled by default (so existing
projects will not be affected) but enabled automatically for new projects
created through `cdk init`.
created through `cdk init`. Existing users can selectively opt in to new
behavior on their own schedule.

The pattern is simple:
Whenever a change leads to CloudFormation template differences that cause any of
the following during an update, it is not safe to apply the new behavior
automatically, and we have to use a feature flag:

- Resources replacement leading to service disruption; or
- Users could have taken assumptions on the old setup and the change will break them.

Adding a new flag looks as follows:

1. Define a new const under
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/lib/features.ts)
Expand All @@ -964,10 +972,11 @@ The pattern is simple:
form `module.Type:feature` (e.g. `@aws-cdk/core:enableStackNameDuplicates`).
2. Use `FeatureFlags.of(construct).isEnabled(cxapi.ENABLE_XXX)` to check if this feature is enabled
in your code. If it is not defined, revert to the legacy behavior.
3. Add your feature flag to the `FUTURE_FLAGS` map in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/lib/features.ts).
This map is inserted to generated `cdk.json` files for new projects created
through `cdk init`.
3. Add your feature flag to the `FLAGS` map in
[cx-api/lib/features.ts](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/lib/features.ts). In
your description, be sure to cover the following:
- Consciously pick the type of feature flag. Can the flag be removed in a future major version, or not?
- Motivate why the feature flag exists. What is the change to existing infrastructure and why is it not safe?
4. Add an entry for your feature flag in the [README](https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/README.md) file.
5. In your tests, ensure that you test your feature with and without the feature flag enabled. You can do this by passing the feature flag to the `context` property when instantiating an `App`.
```ts
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/assert-internal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target":"es2018",
"lib": ["es2016", "es2017.object", "es2017.string"],
"target":"es2020",
"lib": ["es2020"],
"module": "commonjs",
"composite": true,
"declaration": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/assert/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target":"ES2018",
"lib": ["es2018"],
"target":"ES2020",
"lib": ["es2020"],
"module": "CommonJS",
"declaration": true,
"strict": true,
Expand Down
11 changes: 10 additions & 1 deletion packages/@aws-cdk/aws-autoscaling/lib/scheduled-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export interface ScheduledActionProps extends BasicScheduledActionProps {
* Define a scheduled scaling action
*/
export class ScheduledAction extends Resource {
/**
* The name of the scheduled action.
*
* @attribute
*/
public readonly scheduledActionName: string;

constructor(scope: Construct, id: string, props: ScheduledActionProps) {
super(scope, id);

Expand All @@ -100,7 +107,7 @@ export class ScheduledAction extends Resource {
// add a warning on synth when minute is not defined in a cron schedule
props.schedule._bind(this);

new CfnScheduledAction(this, 'Resource', {
const resource = new CfnScheduledAction(this, 'Resource', {
autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
startTime: formatISO(props.startTime),
endTime: formatISO(props.endTime),
Expand All @@ -110,6 +117,8 @@ export class ScheduledAction extends Resource {
recurrence: props.schedule.expressionString,
timeZone: props.timeZone,
});

this.scheduledActionName = resource.attrScheduledActionName;
}
}

Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-autoscaling/test/scheduled-action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ describeDeprecated('scheduled action', () => {
const annotations = Annotations.fromStack(stack).findWarning('*', Match.anyValue());
expect(annotations.length).toBe(0);
});

test('ScheduledActions have a name', () => {
// GIVEN
const stack = new cdk.Stack();
const asg = makeAutoScalingGroup(stack);

const action = asg.scaleOnSchedule('ScaleOutAtMiddaySeoul', {
schedule: autoscaling.Schedule.cron({ hour: '12', minute: '0' }),
minCapacity: 12,
timeZone: 'Asia/Seoul',
});

expect(action.scheduledActionName).toBeDefined();
});
});

function makeAutoScalingGroup(scope: constructs.Construct) {
Expand Down
44 changes: 44 additions & 0 deletions packages/@aws-cdk/aws-codebuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,50 @@ new codebuild.Project(this, 'Project', {
})
```

## Debugging builds interactively using SSM Session Manager

Integration with SSM Session Manager makes it possible to add breakpoints to your
build commands, pause the build there and log into the container to interactively
debug the environment.

To do so, you need to:

* Create the build with `ssmSessionPermissions: true`.
* Use a build image with SSM agent installed and configured (default CodeBuild images come with the image preinstalled).
* Start the build with [debugSessionEnabled](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuild.html#CodeBuild-StartBuild-request-debugSessionEnabled) set to true.

If these conditions are met, execution of the command `codebuild-breakpoint`
will suspend your build and allow you to attach a Session Manager session from
the CodeBuild console.

For more information, see [View a running build in Session
Manager](https://docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html)
in the CodeBuild documentation.

Example:

```ts
new codebuild.Project(this, 'Project', {
environment: {
buildImage: codebuild.LinuxBuildImage.STANDARD_6_0,
},
ssmSessionPermissions: true,
buildSpec: codebuild.BuildSpec.fromObject({
version: '0.2',
phases: {
build: {
commands: [
// Pause the build container if possible
'codebuild-breakpoint',
// Regular build in a script in the repository
'./my-build.sh',
],
},
},
}),
})
```

## Credentials

CodeBuild allows you to store credentials used when communicating with various sources,
Expand Down
41 changes: 41 additions & 0 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,26 @@ export interface CommonProjectProps {
* @default - no explicit limit is set
*/
readonly concurrentBuildLimit?: number

/**
* Add the permissions necessary for debugging builds with SSM Session Manager
*
* If the following prerequisites have been met:
*
* - The necessary permissions have been added by setting this flag to true.
* - The build image has the SSM agent installed (true for default CodeBuild images).
* - The build is started with [debugSessionEnabled](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_StartBuild.html#CodeBuild-StartBuild-request-debugSessionEnabled) set to true.
*
* Then the build container can be paused and inspected using Session Manager
* by invoking the `codebuild-breakpoint` command somewhere during the build.
*
* `codebuild-breakpoint` commands will be ignored if the build is not started
* with `debugSessionEnabled=true`.
*
* @see https://docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html
* @default false
*/
readonly ssmSessionPermissions?: boolean;
}

export interface ProjectProps extends CommonProjectProps {
Expand Down Expand Up @@ -1129,6 +1149,27 @@ export class Project extends ProjectBase {
}));
}

// https://docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html
if (props.ssmSessionPermissions) {
this.addToRolePolicy(new iam.PolicyStatement({
actions: [
// For the SSM channel
'ssmmessages:CreateControlChannel',
'ssmmessages:CreateDataChannel',
'ssmmessages:OpenControlChannel',
'ssmmessages:OpenDataChannel',
// In case the SSM session is set up to log commands to CloudWatch
'logs:DescribeLogGroups',
'logs:CreateLogStream',
'logs:PutLogEvents',
// In case the SSM session is set up to log commands to S3.
's3:GetEncryptionConfiguration',
's3:PutObject',
],
resources: ['*'],
}));
}

if (props.encryptionKey) {
this.encryptionKey = props.encryptionKey;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "21.0.0",
"files": {
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
"source": {
"path": "ReportGroupIntegTestDefaultTestDeployAssert57960C5A.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22.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
@@ -0,0 +1,36 @@
{
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "21.0.0",
"files": {
"38d79637293a2170812ef1108634858c002345d4d5803191fa1d821a30b29d37": {
"source": {
"path": "aws-cdk-codebuild-breakpoint.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "38d79637293a2170812ef1108634858c002345d4d5803191fa1d821a30b29d37.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Loading