-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
ecs.FargateService: from_service_arn_with_cluster not accepting value from SSM Parameter string #30798
ecs.FargateService: from_service_arn_with_cluster not accepting value from SSM Parameter string #30798
Comments
Hi @tisauro, Good morning. Thanks for opening the issue. Although the issue is reproducible using following TypeScript CDK code: import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns';
import * as codepipeline from 'aws-cdk-lib/aws-codepipeline';
import * as pipelineActions from 'aws-cdk-lib/aws-codepipeline-actions'
export class TypescriptStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const albEcsService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
cluster: new ecs.Cluster(this, 'TestCluster', {
clusterName: 'TestCluster'
}),
memoryLimitMiB: 512,
cpu: 0.5,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample')
},
publicLoadBalancer: true,
desiredCount: 1
});
new ssm.StringParameter(this, 'ssmParam', {
parameterName: 'ServiceArn',
stringValue: albEcsService.service.serviceArn
});
const ecsServiceArn = ssm.StringParameter.valueForStringParameter(this, 'ServiceArn');
const ecsService = ecs.FargateService.fromServiceArnWithCluster(this, 'FargateServiceArn', ecsServiceArn);
const deployAction = new pipelineActions.EcsDeployAction({
actionName: 'DeployToStage',
service: ecsService,
imageFile: new codepipeline.ArtifactPath(new codepipeline.Artifact('BuildArtifact'), 'imagedefinitions.json')
});
}
} which gives below error:
The reason we are getting the error is because:
For values which are resolved later during deployment, it appears that these cannot be used as such in static helper method BaseService.fromServiceArnWithCluster(). Thanks, |
Yes fromServiceArnWithCluster() does not handle the serviceArn correctly when it is a Token. aws-cdk/packages/aws-cdk-lib/aws-ecs/lib/base/base-service.ts Lines 516 to 537 in 727e886
The bug is at
We should use Arn.extractResourceName() instead, which handles it well with Token support. See more samples here. Making this a p1 bug and we welcome pull requests. |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
…meter string (aws#30902) ### Issue # (if applicable) Closes aws#30798. ### Reason for this change `fromServiceArnWithCluster()` function can't handle token value correctly. ### Description of changes Replace ``` const resourceName = arn.resourceName; ``` With ``` Arn.extractResourceName() ``` because the function above has the ability to handle token values. ### Description of how you validated changes - Updated the unit test - Manually verified the ECS cluster resource was used in the code pipeline when using the SSM parameter. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
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. |
Describe the bug
When retrieving a Fargate service arn from the parameter store and passing it to the function
from_service_arn_with_cluster
it throws the runtime exception:RuntimeError: Error: resource name ${Token[TOKEN.236]} from service ARN: ${Token[TOKEN.226]} is not using the ARN cluster format
Expected Behavior
accept the format
Current Behavior
raises exception
RuntimeError: Error: resource name ${Token[TOKEN.236]} from service ARN: ${Token[TOKEN.226]} is not using the ARN cluster format
Reproduction Steps
Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.148.0 (build e5740c0)
Framework Version
No response
Node.js Version
v18.19.1
OS
Linux
Language
Python
Language Version
3.9.19
Other information
I am trying to retrieve the ecs service from arn in a different module for passing it to a pipeline action as shown in the example above
The text was updated successfully, but these errors were encountered: