Skip to content

Commit 6da9a4c

Browse files
authored
fix(apprunner-alpha): respect serviceName property (#26238)
Use `serviceName` property when creating CfnService resource. BREAKING CHANGE: This change will be destructive if the `serviceName` is set on an existing resources. Closes #26237 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent fdd3309 commit 6da9a4c

File tree

7 files changed

+34
-38
lines changed

7 files changed

+34
-38
lines changed

packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ export class Service extends cdk.Resource {
10731073
}
10741074

10751075
const resource = new CfnService(this, 'Resource', {
1076+
serviceName: this.props.serviceName,
10761077
instanceConfiguration: {
10771078
cpu: this.props.cpu?.unit,
10781079
memory: this.props.memory?.unit,

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-ecr-public.js.snapshot/integ-apprunner-ecr-public.assets.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"version": "32.0.0",
33
"files": {
4-
"798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215": {
4+
"2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e": {
55
"source": {
66
"path": "integ-apprunner-ecr-public.template.json",
77
"packaging": "file"
88
},
99
"destinations": {
1010
"current_account-current_region": {
1111
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12-
"objectKey": "798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215.json",
12+
"objectKey": "2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e.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-apprunner-alpha/test/integ.service-ecr-public.js.snapshot/integ-apprunner-ecr-public.template.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"EgressConfiguration": {
2020
"EgressType": "DEFAULT"
2121
}
22-
}
22+
},
23+
"ServiceName": "service1"
2324
}
2425
}
2526
},

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-ecr-public.js.snapshot/manifest.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -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}/798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215.json",
20+
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e.json",
2121
"requiresBootstrapStackVersion": 6,
2222
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
2323
"additionalDependencies": [
@@ -36,7 +36,10 @@
3636
"/integ-apprunner-ecr-public/Service1/Resource": [
3737
{
3838
"type": "aws:cdk:logicalId",
39-
"data": "Service1EDCC8134"
39+
"data": "Service1EDCC8134",
40+
"trace": [
41+
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
42+
]
4043
}
4144
],
4245
"/integ-apprunner-ecr-public/URL1": [

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-ecr-public.js.snapshot/tree.json

+2-33
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"egressConfiguration": {
3535
"egressType": "DEFAULT"
3636
}
37-
}
37+
},
38+
"serviceName": "service1"
3839
}
3940
},
4041
"constructInfo": {
@@ -56,38 +57,6 @@
5657
"version": "0.0.0"
5758
}
5859
},
59-
"ServiceName": {
60-
"id": "ServiceName",
61-
"path": "integ-apprunner-ecr-public/ServiceName",
62-
"constructInfo": {
63-
"fqn": "aws-cdk-lib.CfnOutput",
64-
"version": "0.0.0"
65-
}
66-
},
67-
"ServiceId": {
68-
"id": "ServiceId",
69-
"path": "integ-apprunner-ecr-public/ServiceId",
70-
"constructInfo": {
71-
"fqn": "aws-cdk-lib.CfnOutput",
72-
"version": "0.0.0"
73-
}
74-
},
75-
"ServiceStatus": {
76-
"id": "ServiceStatus",
77-
"path": "integ-apprunner-ecr-public/ServiceStatus",
78-
"constructInfo": {
79-
"fqn": "aws-cdk-lib.CfnOutput",
80-
"version": "0.0.0"
81-
}
82-
},
83-
"ServiceArn": {
84-
"id": "ServiceArn",
85-
"path": "integ-apprunner-ecr-public/ServiceArn",
86-
"constructInfo": {
87-
"fqn": "aws-cdk-lib.CfnOutput",
88-
"version": "0.0.0"
89-
}
90-
},
9160
"BootstrapVersion": {
9261
"id": "BootstrapVersion",
9362
"path": "integ-apprunner-ecr-public/BootstrapVersion",

packages/@aws-cdk/aws-apprunner-alpha/test/integ.service-ecr-public.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const stack = new cdk.Stack(app, 'integ-apprunner-ecr-public');
77

88
// Scenario 1: Create the service from ECR public
99
const service1 = new Service(stack, 'Service1', {
10+
serviceName: 'service1',
1011
source: Source.fromEcrPublic({
1112
imageConfiguration: {
1213
port: 8000,

packages/@aws-cdk/aws-apprunner-alpha/test/service.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,27 @@ test('autoDeploymentsEnabled flag is NOT set', () => {
12331233
});
12341234
});
12351235

1236+
test('serviceName is set', () => {
1237+
// GIVEN
1238+
const app = new cdk.App();
1239+
const stack = new cdk.Stack(app, 'demo-stack');
1240+
const serviceName = 'demo-service';
1241+
// WHEN
1242+
new apprunner.Service(stack, 'DemoService', {
1243+
serviceName: serviceName,
1244+
source: apprunner.Source.fromGitHub({
1245+
repositoryUrl: 'https://github.com/aws-containers/hello-app-runner',
1246+
branch: 'main',
1247+
configurationSource: apprunner.ConfigurationSourceType.REPOSITORY,
1248+
connection: apprunner.GitHubConnection.fromConnectionArn('MOCK'),
1249+
}),
1250+
});
1251+
// THEN
1252+
Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::Service', {
1253+
ServiceName: serviceName,
1254+
});
1255+
});
1256+
12361257
testDeprecated('Using both environmentVariables and environment should throw an error', () => {
12371258
const app = new cdk.App();
12381259
const stack = new cdk.Stack(app, 'demo-stack');

0 commit comments

Comments
 (0)