aws / aws/aws-cdk

[core] Prefix mutable L1 properties with `prop`

Open
#11,667 0 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/core cause/l1-name-instead-of-ref effort/medium feature-request p2 package/cfn wontfix
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

It's quite common for people to be using L1s, and then try to refer to the name of the recently-generated resource by using the name property.

For example:

```ts
const dashboard = new CfnDashboard(...);

new Something(..., {
dashboardName: dashboard.dashboardName, // <---- wrooooong
});
```

This looks seductive and sane, but is actually wrong. `dashboardName` is a mutable version of the (input) property, and typically `undefined`, NOT a reference generated/calculated name of the resource (`{ Ref }`), which also implies a dependency.

The correct usage would have been:

```ts
dashboard.attrDashboardName
dashboard.ref
```

Depending on the use case.

People get this wrong all the time, because it's a CFN quirk that we expect people to be familiar with, but they're not.

Bug reports caused by this design mistake:

https://github.com/aws/aws-cdk/issues?q=is%3Aissue+label%3Acause%2Fl1-name-instead-of-ref+is%3Aclosed

A good solution would probably be to deprecate the old property names and properly prefix them with `prop` (`propDashboardName`).

Hopefully that will give people a fighting chance figuring out what they're looking for.

Probably needs to be prioritized for v2 because after V2 the deprecation (but availability) of the old property names means people will continue making the same mistakes.

---

This is a :rocket: Feature Request

Contributor guide

Open the contributing guide

Research direction

Start by tracing how L1 mutable properties are generated and review the closed reports in the linked cause/l1-name-instead-of-ref search. Done means mutable properties expose prop-prefixed names while the old names remain available as deprecated aliases, including examples such as dashboardName, attrDashboardName, and ref.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.