-
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
fix(ecs): new arn format not supported (under feature flag) #18140
Changes from 1 commit
3223be3
f5a3560
b5c9bf5
a534380
dc8bcff
30546e6
010502e
2a2a047
728a094
8f67295
5b145a7
6a05966
dd295d8
92136f2
4db80e2
66b087f
c3097a7
afe21d9
9caa1a5
a22ef04
764d034
f88e7fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||
import { ArnFormat, Lazy, Resource, Stack } from '@aws-cdk/core'; | ||
import { ArnFormat, FeatureFlags, Fn, Lazy, Resource, Stack, Token } from '@aws-cdk/core'; | ||
import { ECS_ARN_FORMAT_INCLUDES_CLUSTER_NAME } from '@aws-cdk/cx-api'; | ||
import { Construct } from 'constructs'; | ||
import { BaseService, BaseServiceOptions, DeploymentControllerType, IBaseService, IService, LaunchType } from '../base/base-service'; | ||
import { fromServiceAtrributes } from '../base/from-service-attributes'; | ||
|
@@ -128,9 +129,25 @@ export class Ec2Service extends BaseService implements IEc2Service { | |
public static fromEc2ServiceArn(scope: Construct, id: string, ec2ServiceArn: string): IEc2Service { | ||
class Import extends Resource implements IEc2Service { | ||
public readonly serviceArn = ec2ServiceArn; | ||
public readonly serviceName = Stack.of(scope).splitArn(ec2ServiceArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName as string; | ||
public readonly serviceName: string; | ||
constructor() { | ||
super(scope, id); | ||
const resourceName = Stack.of(scope).splitArn(ec2ServiceArn, ArnFormat.SLASH_RESOURCE_NAME).resourceName as string; | ||
if (Token.isUnresolved(ec2ServiceArn)) { | ||
if (FeatureFlags.of(this).isEnabled(ECS_ARN_FORMAT_INCLUDES_CLUSTER_NAME)) { | ||
const components = Fn.split(':', ec2ServiceArn); | ||
const lastComponents = Fn.split('/', Fn.select(5, components)); | ||
this.serviceName = Fn.select(2, lastComponents); | ||
} else { | ||
this.serviceName = resourceName; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This logic is repeated (or at least extremely similar) here, in fargate-service.ts and in from-service-attributes.ts. We should factor this out to one place. It could probably be shared from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the code to a new function |
||
} else { | ||
const resourceNameSplit = resourceName.split('/'); | ||
this.serviceName = resourceNameSplit.length === 1 ? resourceName : resourceNameSplit[1]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be factored out to one place as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the code to a new function |
||
} | ||
} | ||
} | ||
return new Import(scope, id); | ||
return new Import(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be missing something here, but I don't understand this. Can you explain why is this changing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, passing the parameters was necessary because they were passed to the super class. The new implementation contains a constructor. In this case, the If you prefer the existing code ( constructor(importScope: Construct, importId: string) {
super(importScope, importId);
// ...
}
}
return new Import(scope, id); However, we have to use new attribute names. If I use Which option do you prefer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No constructor is used anymore --> done. |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you create a new construct to check the feature flags on here? Shouldn't it be possible to just do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried
FeatureFlags.of(scope)
first because it should be the preferred solution. Unfortunately, it causes this error:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since FeatureFlags expects a
Construct
from the core library, I think we can just switch to using that one in thefromServiceAttributes()
function. I pushed this change to your branch, waiting for the build to see if this has other impacts.