Skip to content

Commit 7d17fe3

Browse files
authored
fix(ivs): Not a standard physical name pattern (#24706)
## Summary - change physical name of Props to `<cfnResource>Name` (e.g channelName) - generate physical name by CDK if not present ## Why need this change Because the alpha package `aws-ivs` does not follow standard CDK physical name conventions. CDK expects an auto-generated physical name to be used if the physical name is omitted. This will result in the "Use generated resource names, not physical names " of [Best practice](https://docs.aws.amazon.com/cdk/v2/guide/best-practices.html#best-practices-apps-names) can be complied with. However, the current `aws-ivs` package configuration does not follow that rule, so if omitted, the resource will be created without a physical name. Being created without a physical name is inconvenient for resource management, and many customers are forced to use physical names explicitly. Also, the standard CDK naming convention for the physical name property should be of the form `<cfnResource>Name` like bucketName, but the IVS package is just `name` and does not conform to the standard. ## Why changes now Resolving these issues would require breaking changes and should be resolved before migrating to the stable package. ## Related issues Closes none. BREAKING CHANGE: Renamed ChannelProps.name to ChannelProps.channelName * Renamed PlaybackKeyPairProps.name to PlaybackKeyPairProps.playbackKeyPairName * Channel now generates a physical name if one is not provided * PlaybackKeyPair now generates a physical name if one is not provided ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a51346e commit 7d17fe3

12 files changed

+282
-158
lines changed

packages/@aws-cdk/aws-ivs/lib/channel.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@aws-cdk/core';
2+
import { Lazy, Names } from '@aws-cdk/core';
23
import { Construct } from 'constructs';
34
import { CfnChannel } from './ivs.generated';
45
import { StreamKey } from './stream-key';
@@ -93,11 +94,11 @@ export interface ChannelProps {
9394
readonly latencyMode?: LatencyMode;
9495

9596
/**
96-
* Channel name.
97+
* A name for the channel.
9798
*
98-
* @default - None
99+
* @default Automatically generated name
99100
*/
100-
readonly name?: string;
101+
readonly channelName?: string;
101102

102103
/**
103104
* The channel type, which determines the allowable resolution and bitrate.
@@ -152,17 +153,19 @@ export class Channel extends ChannelBase {
152153

153154
constructor(scope: Construct, id: string, props: ChannelProps = {}) {
154155
super(scope, id, {
155-
physicalName: props.name,
156+
physicalName: props.channelName ?? Lazy.string({
157+
produce: () => Names.uniqueResourceName(this, { maxLength: 128, allowedSpecialCharacters: '-_' }),
158+
}),
156159
});
157160

158-
if (props.name && !core.Token.isUnresolved(props.name) && !/^[a-zA-Z0-9-_]*$/.test(props.name)) {
159-
throw new Error(`name must contain only numbers, letters, hyphens and underscores, got: '${props.name}'`);
161+
if (this.physicalName && !core.Token.isUnresolved(this.physicalName) && !/^[a-zA-Z0-9-_]*$/.test(this.physicalName)) {
162+
throw new Error(`channelName must contain only numbers, letters, hyphens and underscores, got: '${this.physicalName}'`);
160163
}
161164

162165
const resource = new CfnChannel(this, 'Resource', {
163166
authorized: props.authorized,
164167
latencyMode: props.latencyMode,
165-
name: props.name,
168+
name: this.physicalName,
166169
type: props.type,
167170
});
168171

packages/@aws-cdk/aws-ivs/lib/playback-key-pair.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as core from '@aws-cdk/core';
2+
import { Lazy, Names } from '@aws-cdk/core';
23
import { Construct } from 'constructs';
34
import { CfnPlaybackKeyPair } from './ivs.generated';
45

@@ -35,9 +36,9 @@ export interface PlaybackKeyPairProps {
3536
* An arbitrary string (a nickname) assigned to a playback key pair that helps the customer identify that resource.
3637
* The value does not need to be unique.
3738
*
38-
* @default None
39+
* @default Automatically generated name
3940
*/
40-
readonly name?: string;
41+
readonly playbackKeyPairName?: string;
4142
}
4243

4344
/**
@@ -54,15 +55,19 @@ export class PlaybackKeyPair extends PlaybackKeyPairBase {
5455
public readonly playbackKeyPairFingerprint: string;
5556

5657
constructor(scope: Construct, id: string, props: PlaybackKeyPairProps) {
57-
super(scope, id, {});
58+
super(scope, id, {
59+
physicalName: props.playbackKeyPairName ?? Lazy.string({
60+
produce: () => Names.uniqueResourceName(this, { maxLength: 128, allowedSpecialCharacters: '-_' }),
61+
}),
62+
});
5863

59-
if (props.name && !core.Token.isUnresolved(props.name) && !/^[a-zA-Z0-9-_]*$/.test(props.name)) {
60-
throw new Error(`name must contain only numbers, letters, hyphens and underscores, got: '${props.name}'`);
64+
if (props.playbackKeyPairName && !core.Token.isUnresolved(props.playbackKeyPairName) && !/^[a-zA-Z0-9-_]*$/.test(props.playbackKeyPairName)) {
65+
throw new Error(`playbackKeyPairName must contain only numbers, letters, hyphens and underscores, got: '${props.playbackKeyPairName}'`);
6166
}
6267

6368
const resource = new CfnPlaybackKeyPair(this, 'Resource', {
6469
publicKeyMaterial: props.publicKeyMaterial,
65-
name: props.name,
70+
name: props.playbackKeyPairName,
6671
});
6772

6873
this.playbackKeyPairArn = resource.attrArn;

packages/@aws-cdk/aws-ivs/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
},
4141
"awslint": {
4242
"exclude": [
43-
"props-physical-name:@aws-cdk/aws-ivs.ChannelProps",
4443
"props-physical-name:@aws-cdk/aws-ivs.StreamKeyProps",
45-
"props-physical-name:@aws-cdk/aws-ivs.PlaybackKeyPairProps",
4644
"from-method:@aws-cdk/aws-ivs.StreamKey",
4745
"from-method:@aws-cdk/aws-ivs.PlaybackKeyPair"
4846
]

packages/@aws-cdk/aws-ivs/test/integ.ivs.js.snapshot/aws-cdk-ivs.assets.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"version": "30.0.0",
2+
"version": "31.0.0",
33
"files": {
4-
"71d02f468f201d8c79d33a72cd8debac3b538f4e0efb492c6c06aca0055029f8": {
4+
"fef396e89f5ce4eed5b6b04937e297b9abeab6a5db8cd808498a20aca8c61ef3": {
55
"source": {
66
"path": "aws-cdk-ivs.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "71d02f468f201d8c79d33a72cd8debac3b538f4e0efb492c6c06aca0055029f8.json",
12+
"objectKey": "fef396e89f5ce4eed5b6b04937e297b9abeab6a5db8cd808498a20aca8c61ef3.json",
1313
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
1414
}
1515
}

packages/@aws-cdk/aws-ivs/test/integ.ivs.js.snapshot/aws-cdk-ivs.template.json

+22-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
{
22
"Resources": {
3-
"PlaybackKeyPairBE17315B": {
3+
"DefaultPropertiesPlaybackKeyPairaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaB5D4BE27": {
4+
"Type": "AWS::IVS::PlaybackKeyPair",
5+
"Properties": {
6+
"PublicKeyMaterial": "-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEHBm/D9UFf1z4czcAFuM7w+tstxxzoLVo\nfa1OT0gQjRYsy/YTcrKI5FS7ur3NZIcmiwqerr7dP0wSZjfEMNe82W1zWdkxHJ6Y\n73g9gZDxwGdjowZjEOIvAeH2Of6NeDOo\n-----END PUBLIC KEY-----"
7+
}
8+
},
9+
"DefaultPropertiesChannelaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa201FBD46": {
10+
"Type": "AWS::IVS::Channel",
11+
"Properties": {
12+
"Name": "aws-cdk-ivsDefaultPropertiesChannel-_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaEDEAEDA9"
13+
}
14+
},
15+
"AllPropertiesPlaybackKeyPair96291E97": {
416
"Type": "AWS::IVS::PlaybackKeyPair",
517
"Properties": {
618
"Name": "IVSIntegrationTestPlaybackKeyPair",
719
"PublicKeyMaterial": "-----BEGIN PUBLIC KEY-----\nMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEs6k8Xf6WyFq3yZXoup8G/gH6DntSATqD\nYfo83eX0GJCKxJ8fr09h9LP9HDGof8/bo66P+SGHeAARGF/O9WPAQVUgSlm/KMFX\nEPtPtOm1s0GR9k1ydU5hkI++f9CoZ5lM\n-----END PUBLIC KEY-----"
820
}
921
},
10-
"Channel4048F119": {
22+
"AllPropertiesChannel737C871D": {
1123
"Type": "AWS::IVS::Channel",
1224
"Properties": {
1325
"Authorized": true,
@@ -16,39 +28,39 @@
1628
"Type": "BASIC"
1729
}
1830
},
19-
"StreamKey9F296F4F": {
31+
"AllPropertiesStreamKey2A169FFE": {
2032
"Type": "AWS::IVS::StreamKey",
2133
"Properties": {
2234
"ChannelArn": {
2335
"Fn::GetAtt": [
24-
"Channel4048F119",
36+
"AllPropertiesChannel737C871D",
2537
"Arn"
2638
]
2739
}
2840
}
2941
}
3042
},
3143
"Outputs": {
32-
"PlaybackKeyPairArn": {
44+
"AllPropertiesPlaybackKeyPairArn9C29D23B": {
3345
"Value": {
3446
"Fn::GetAtt": [
35-
"PlaybackKeyPairBE17315B",
47+
"AllPropertiesPlaybackKeyPair96291E97",
3648
"Arn"
3749
]
3850
}
3951
},
40-
"ChannelArn": {
52+
"AllPropertiesChannelArn97A102C5": {
4153
"Value": {
4254
"Fn::GetAtt": [
43-
"Channel4048F119",
55+
"AllPropertiesChannel737C871D",
4456
"Arn"
4557
]
4658
}
4759
},
48-
"StreamKeyArn": {
60+
"AllPropertiesStreamKeyArnB62C0761": {
4961
"Value": {
5062
"Fn::GetAtt": [
51-
"StreamKey9F296F4F",
63+
"AllPropertiesStreamKey2A169FFE",
5264
"Arn"
5365
]
5466
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"30.0.0"}
1+
{"version":"31.0.0"}

packages/@aws-cdk/aws-ivs/test/integ.ivs.js.snapshot/integ.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "30.0.0",
2+
"version": "31.0.0",
33
"testCases": {
44
"ivs-test/DefaultTest": {
55
"stacks": [

packages/@aws-cdk/aws-ivs/test/integ.ivs.js.snapshot/ivstestDefaultTestDeployAssertDCE80D47.assets.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "30.0.0",
2+
"version": "31.0.0",
33
"files": {
44
"21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": {
55
"source": {

packages/@aws-cdk/aws-ivs/test/integ.ivs.js.snapshot/manifest.json

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "30.0.0",
2+
"version": "31.0.0",
33
"artifacts": {
44
"aws-cdk-ivs.assets": {
55
"type": "cdk:asset-manifest",
@@ -17,7 +17,7 @@
1717
"validateOnSynth": false,
1818
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
1919
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
20-
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/71d02f468f201d8c79d33a72cd8debac3b538f4e0efb492c6c06aca0055029f8.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/fef396e89f5ce4eed5b6b04937e297b9abeab6a5db8cd808498a20aca8c61ef3.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -33,40 +33,52 @@
3333
"aws-cdk-ivs.assets"
3434
],
3535
"metadata": {
36-
"/aws-cdk-ivs/PlaybackKeyPair/Resource": [
36+
"/aws-cdk-ivs/DefaultProperties/PlaybackKeyPair-_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Resource": [
3737
{
3838
"type": "aws:cdk:logicalId",
39-
"data": "PlaybackKeyPairBE17315B"
39+
"data": "DefaultPropertiesPlaybackKeyPairaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaB5D4BE27"
4040
}
4141
],
42-
"/aws-cdk-ivs/Channel/Resource": [
42+
"/aws-cdk-ivs/DefaultProperties/Channel-_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Resource": [
4343
{
4444
"type": "aws:cdk:logicalId",
45-
"data": "Channel4048F119"
45+
"data": "DefaultPropertiesChannelaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa201FBD46"
4646
}
4747
],
48-
"/aws-cdk-ivs/StreamKey/Resource": [
48+
"/aws-cdk-ivs/AllProperties/PlaybackKeyPair/Resource": [
4949
{
5050
"type": "aws:cdk:logicalId",
51-
"data": "StreamKey9F296F4F"
51+
"data": "AllPropertiesPlaybackKeyPair96291E97"
5252
}
5353
],
54-
"/aws-cdk-ivs/PlaybackKeyPairArn": [
54+
"/aws-cdk-ivs/AllProperties/Channel/Resource": [
5555
{
5656
"type": "aws:cdk:logicalId",
57-
"data": "PlaybackKeyPairArn"
57+
"data": "AllPropertiesChannel737C871D"
5858
}
5959
],
60-
"/aws-cdk-ivs/ChannelArn": [
60+
"/aws-cdk-ivs/AllProperties/StreamKey/Resource": [
6161
{
6262
"type": "aws:cdk:logicalId",
63-
"data": "ChannelArn"
63+
"data": "AllPropertiesStreamKey2A169FFE"
6464
}
6565
],
66-
"/aws-cdk-ivs/StreamKeyArn": [
66+
"/aws-cdk-ivs/AllProperties/PlaybackKeyPairArn": [
6767
{
6868
"type": "aws:cdk:logicalId",
69-
"data": "StreamKeyArn"
69+
"data": "AllPropertiesPlaybackKeyPairArn9C29D23B"
70+
}
71+
],
72+
"/aws-cdk-ivs/AllProperties/ChannelArn": [
73+
{
74+
"type": "aws:cdk:logicalId",
75+
"data": "AllPropertiesChannelArn97A102C5"
76+
}
77+
],
78+
"/aws-cdk-ivs/AllProperties/StreamKeyArn": [
79+
{
80+
"type": "aws:cdk:logicalId",
81+
"data": "AllPropertiesStreamKeyArnB62C0761"
7082
}
7183
],
7284
"/aws-cdk-ivs/BootstrapVersion": [

0 commit comments

Comments
 (0)