Skip to content

Commit

Permalink
feat: add fromArn method
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed May 28, 2024
1 parent a4e11b4 commit e73b10d
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface IObservabilityConfiguration extends cdk.IResource {
*/
export class ObservabilityConfiguration extends cdk.Resource implements IObservabilityConfiguration {
/**
* Import from Observability configuration attributes.
* Imports an App Runner Observability Configuration from attributes.
*/
public static fromObservabilityConfigurationAttributes(scope: Construct, id: string,
attrs: ObservabilityConfigurationAttributes): IObservabilityConfiguration {
Expand All @@ -98,6 +98,28 @@ export class ObservabilityConfiguration extends cdk.Resource implements IObserva
return new Import(scope, id);
}

/**
* Imports an App Runner Observability Configuration from its ARN
*/
public static fromArn(scope: Construct, id: string, observabilityConfigurationArn: string): IObservabilityConfiguration {
const arn = cdk.Stack.of(scope).splitArn(observabilityConfigurationArn, cdk.ArnFormat.SLASH_RESOURCE_NAME);

const resourceParts = arn.resourceName?.split('/');

if (!resourceParts || resourceParts.length < 3) {
throw new Error(`Unexpected ARN format: ${observabilityConfigurationArn}`);
}

const observabilityConfigurationName = resourceParts[0];
const observabilityConfigurationRevision = parseInt(resourceParts[1]);

return ObservabilityConfiguration.fromObservabilityConfigurationAttributes(scope, id, {
observabilityConfigurationArn,
observabilityConfigurationName,
observabilityConfigurationRevision,
});
}

/**
* The ARN of the Observability configuration.
* @attribute
Expand Down

0 comments on commit e73b10d

Please sign in to comment.