Skip to content

Conversation

@rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Mar 20, 2025

Assets created by the AWS Construct Library now use friendly display names.

  • Assets like stack templates now show a display name like MyStack Template.
  • Assets from Asset or ImageAsset constructs now show the stack-relative construct path of the asset construct, like MyConstruct/MyFunction/Code.

These defaults explicitly don't use entire construct paths on purpose, because those will be confusing in combination with the deduplication behavior of assets; if the same asset is added in multiple places in the construct tree, it will be deduplicated (based on the asset hash) and only processed once. The defaults have therefore been chosen to give useful contextual information, without implying a context that will alarm users.

For example, it would be confusing for users to see references to /MyBetaStage/MyStack Template or /MyBetaStack/MyFunction/Code when they were deploying a "prod" environment; but if we used full context paths and the Beta resources were defined first, that would be the default behavior.

A displayName property is available to override the default if the defaults are undesirable. This property is available for Asset/AssetImage constructs and their helper functions, not for template assets.

Impact of this change

The new display name isn't used anywhere that impacts resource replacement. Your resources will deploy the same as they did before.

You will see this new name in CLI progress information, and in the action names of CDK Pipelines.

Any CDK Pipelines will self-mutate one additional time to show the new asset names, and will remain stable afterwards.

Implementation notes

Since in the cloud assembly displayName is part of neither asset source not asset destination, but an additional field, I've had to add a 3rd parameter Add*AssetOptions to most of the add*Asset() methods and it needs to be forwarded in a number of places.

The CDK Pipelines implementation also needed to add the concept of a displayName to pipeline graph nodes, since reflecting it in the node IDs had far-reaching consequences (the node ID also affects the construct IDs of constructs that get created, and we don't want to have to recreate these just for a different display name). Uniquification of action names happens at the very last moment, when we put the Pipeline together.

GraphNode.of() accepts positional parameters so I added a positional optional argument for display name there, but since in TypeScript subclasses have to be structurally compatible with superclasses (😶‍🌫️) and Graph.of() already takes an argument in that position, the type of that argument is now weird. The alternative would be to change the signature to Graph.of(id, data, <displayName?>, nodes?), inserting displayName, but even though this is not part of the super public jsii interface this method is still accessible on the semi-public "extend me via TypeScript only" interface and we don't want to unnecessarily break consumers.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Assets created by the AWS Construct Library now use friendly display names.

- Assets like stack templates now show a display name like `MyStack Template`.
- Assets from `Asset` or `ImageAsset` constructs now show the
  stack-relative construct path of the asset construct, like
  `MyConstruct/MyFunction/Code`.

These defaults explicitly don't use entire construct paths on purpose,
because those will be confusing in combination with the deduplication
behavior of assets; if the same asset is added in multiple places in the
construct tree, it will be deduplicated (based on the asset hash) and
only processed once. The defaults have therefore been chosen to give
useful contextual information, without implying a context that will
alarm users.

For example, it would be confusing for users to see references to
`/MyBetaStage/MyStack Template` or `/MyBetaStack/MyFunction/Code` when
they were deploying a "prod" environment; but if we used full context
paths and the Beta resources were defined first, that would be the
default behavior.

A `displayName` property is available to override the default if the
defaults are undesirable. This property is available for
Asset/AssetImage constructs and their helper functions, not for template
assets.
@rix0rrr rix0rrr self-assigned this Mar 20, 2025
@github-actions github-actions bot added the p2 label Mar 20, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team March 20, 2025 10:34
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Mar 20, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@codecov
Copy link

codecov bot commented Mar 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.38%. Comparing base (56586f4) to head (8547897).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #33844      +/-   ##
==========================================
+ Coverage   82.35%   82.38%   +0.03%     
==========================================
  Files         120      120              
  Lines        6941     6955      +14     
  Branches     1172     1173       +1     
==========================================
+ Hits         5716     5730      +14     
  Misses       1120     1120              
  Partials      105      105              
Flag Coverage Δ
suite.unit 82.38% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.38% <100.00%> (+0.03%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rix0rrr rix0rrr added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Mar 20, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 20, 2025 19:10

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

buildSpecString: actualBuildSpec.toBuildSpec(),
}));

const actionName = options.actionName ?? this.stepId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This never did anything. The type of actionName is string (not string | undefined).

@rix0rrr rix0rrr marked this pull request as ready for review March 22, 2025 13:34
@rix0rrr rix0rrr requested a review from a team as a code owner March 22, 2025 13:34
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Mar 22, 2025

Do we think this makes sense, or would we rather just have the word "template" here?

image

Default asset naming in a pipeline with sanitized action names:

image

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Mar 24, 2025

Build failures are due to integ-runner not supporting the new cloud assembly schema yet. Needs a release.

@mergify
Copy link
Contributor

mergify bot commented Mar 26, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 8547897
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Mar 27, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 4e958d4 into main Mar 27, 2025
20 checks passed
@mergify mergify bot deleted the huijbers/asset-naming branch March 27, 2025 10:02
@github-actions
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants