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

fix(custom-resources): log group name for waiter state machine does not start with /aws/vendedlogs/states/ (under feature flag) #28587

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/@aws-cdk/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Flags come in three types:
| [@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters](#aws-cdkaws-rdsauroraclusterchangescopeofinstanceparametergroupwitheachparameters) | When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change. | 2.97.0 | (fix) |
| [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) |
| [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) |
| [@aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler](#aws-cdkcustom-resourceschangedefaultloggroupnameforwaiterstatemachineincompletehandler) | When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`. | V2NEXT | (fix) |

<!-- END table -->

Expand Down Expand Up @@ -116,7 +117,8 @@ The following json shows the current recommended set of flags, as `cdk init` wou
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-codepipeline-actions:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler": true
}
}
```
Expand Down Expand Up @@ -1193,4 +1195,18 @@ However, with the activation of this feature flag, the default branch is updated
| 2.103.1 | `false` | `true` |


### @aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler

*When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`.* (fix)

If this is set, the log group name of a generated log group in `WaiterStateMachine` construct which is
created by `Provider` construct with `CompleteHandler` will start with `/aws/vendedlogs/states`.


| Since | Default | Recommended |
| ----- | ----- | ----- |
| (not in v1) | | |
| V2NEXT | `false` | `true` |


<!-- END details -->
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Grant, IGrantable, PolicyStatement, Role, ServicePrincipal } from '../.
import { IFunction } from '../../../aws-lambda';
import { ILogGroup, LogGroup } from '../../../aws-logs';
import { CfnStateMachine, LogLevel } from '../../../aws-stepfunctions';
import { Duration, Stack } from '../../../core';
import { Duration, FeatureFlags, Stack } from '../../../core';
import * as cxapi from '../../../cx-api';

/**
* Log Options for the state machine.
Expand Down Expand Up @@ -172,7 +173,16 @@ export class WaiterStateMachine extends Construct {
resources: ['*'],
}));

const logGroup = logOptions?.destination ?? new LogGroup(this, 'LogGroup');
// Using `node.addr` because it needs to be a unique log group name in the AWS account,
// not using `node.path` because of the possibility of exceeding the maximum number of characters for the log group name.
// The `addr` value does not change when moving the construct tree using the ID `Default`.
const logGroupName =
FeatureFlags.of(this).isEnabled(cxapi.WAITER_STATE_MACHINE_LOG_GROUP_NAME)
? `/aws/vendedlogs/states/waiter-state-machine-${this.node.addr}-Logs`
: undefined;
const logGroup = logOptions?.destination ?? new LogGroup(this, 'LogGroup', {
logGroupName,
});

return {
destinations: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,39 @@ describe('state machine', () => {
});
Template.fromStack(stack).resourceCountIs('AWS::Logs::LogGroup', 1);
});

test('log group name is specified if the feature flag is set', () => {
// GIVEN
const stack = new Stack();
Node.of(stack).setContext('@aws-cdk/core:target-partitions', ['aws', 'aws-cn']);
Node.of(stack).setContext('@aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler', true);

const isCompleteHandler = new lambdaFn(stack, 'isComplete', {
code: Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});
const timeoutHandler = new lambdaFn(stack, 'isTimeout', {
code: Code.fromInline('foo'),
runtime: lambda.Runtime.NODEJS_LATEST,
handler: 'index.handler',
});
const interval = Duration.hours(2);
const maxAttempts = 2;
const backoffRate = 5;

// WHEN
new WaiterStateMachine(stack, 'statemachine', {
isCompleteHandler,
timeoutHandler,
backoffRate,
interval,
maxAttempts,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Logs::LogGroup', {
LogGroupName: '/aws/vendedlogs/states/waiter-state-machine-c892b744a2306a661f17f50ce17de4b606ce3fc700-Logs',
});
});
});
18 changes: 17 additions & 1 deletion packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Flags come in three types:
| [@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters](#aws-cdkaws-rdsauroraclusterchangescopeofinstanceparametergroupwitheachparameters) | When enabled, a scope of InstanceParameterGroup for AuroraClusterInstance with each parameters will change. | 2.97.0 | (fix) |
| [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) |
| [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) |
| [@aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler](#aws-cdkcustom-resourceschangedefaultloggroupnameforwaiterstatemachineincompletehandler) | When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`. | V2NEXT | (fix) |

<!-- END table -->

Expand Down Expand Up @@ -116,7 +117,8 @@ The following json shows the current recommended set of flags, as `cdk init` wou
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-codepipeline-actions:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler": true
}
}
```
Expand Down Expand Up @@ -1193,4 +1195,18 @@ However, with the activation of this feature flag, the default branch is updated
| 2.103.1 | `false` | `true` |


### @aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler

*When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`.* (fix)

If this is set, the log group name of a generated log group in `WaiterStateMachine` construct which is
created by `Provider` construct with `CompleteHandler` will start with `/aws/vendedlogs/states`.


| Since | Default | Recommended |
| ----- | ----- | ----- |
| (not in v1) | | |
| V2NEXT | `false` | `true` |


<!-- END details -->
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/cx-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,20 @@ _cdk.json_
}
}
```

* `@aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler`

When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`.

If this is set, the log group name of a generated log group in `WaiterStateMachine` construct which is
created by `Provider` construct with `CompleteHandler` will start with `/aws/vendedlogs/states`.

_cdk.json_

```json
{
"context": {
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true
}
}
```
13 changes: 13 additions & 0 deletions packages/aws-cdk-lib/cx-api/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const RDS_PREVENT_RENDERING_DEPRECATED_CREDENTIALS = '@aws-cdk/aws-rds:pr
export const AURORA_CLUSTER_CHANGE_SCOPE_OF_INSTANCE_PARAMETER_GROUP_WITH_EACH_PARAMETERS = '@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters';
export const APPSYNC_ENABLE_USE_ARN_IDENTIFIER_SOURCE_API_ASSOCIATION = '@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier';
export const CODECOMMIT_SOURCE_ACTION_DEFAULT_BRANCH_NAME = '@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource';
export const WAITER_STATE_MACHINE_LOG_GROUP_NAME = '@aws-cdk/custom-resources:changeDefaultLogGroupNameForWaiterStateMachineInCompleteHandler';

export const FLAGS: Record<string, FlagInfo> = {
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -976,6 +977,18 @@ export const FLAGS: Record<string, FlagInfo> = {
introducedIn: { v2: '2.103.1' },
recommendedValue: true,
},

//////////////////////////////////////////////////////////////////////
[WAITER_STATE_MACHINE_LOG_GROUP_NAME]: {
type: FlagType.BugFix,
summary: 'When enabled, the log group name for waiter state machine in CompleteHandler will start with `/aws/vendedlogs/states`.',
detailsMd: `
If this is set, the log group name of a generated log group in \`WaiterStateMachine\` construct which is
created by \`Provider\` construct with \`CompleteHandler\` will start with \`/aws/vendedlogs/states\`.
`,
introducedIn: { v2: 'V2NEXT' },
recommendedValue: true,
},
};

const CURRENT_MV = 'v2';
Expand Down
Loading