12
12
*/
13
13
14
14
15
- import { aws_bedrock as bedrock } from 'aws-cdk-lib' ;
15
+ import { Arn , ArnFormat , aws_bedrock as bedrock , Resource } from 'aws-cdk-lib' ;
16
16
import { Construct } from 'constructs' ;
17
17
18
18
19
+ /**
20
+ * Interface for both Imported and CDK-created Agent Aliases.
21
+ */
22
+ export interface IAgentAlias {
23
+ /**
24
+ * The unique identifier of the agent alias.
25
+ * @example `TCLCITFZTN`
26
+ */
27
+ readonly aliasId : string ;
28
+ /**
29
+ * The unique identifier of the agent.
30
+ * @example `DNCJJYQKSU`
31
+ */
32
+ readonly agentId : string ;
33
+ /**
34
+ * The ARN of the agent alias.
35
+ * @example `arn:aws:bedrock:us-east-1:123456789012:agent-alias/DNCJJYQKSU/TCLCITFZTN`
36
+ */
37
+ readonly aliasArn : string ;
38
+ }
39
+
40
+ /**
41
+ * Interface to create a new Agent Alias.
42
+ */
19
43
export interface AgentAliasProps {
20
44
/**
21
45
* The unique identifier of the agent.
@@ -27,7 +51,6 @@ export interface AgentAliasProps {
27
51
* @default - 'latest'
28
52
*/
29
53
readonly aliasName ?: string ;
30
-
31
54
/**
32
55
* Description for the agent alias.
33
56
*
@@ -52,13 +75,48 @@ export interface AgentAliasProps {
52
75
readonly tags ?: Record < string , string > ;
53
76
}
54
77
55
- export class AgentAlias extends Construct {
78
+ export class AgentAlias extends Construct implements IAgentAlias {
79
+ // ------------------------------------------------------
80
+ // Imports
81
+ // ------------------------------------------------------
82
+ /**
83
+ * Brings an Agent Alias from an existing one created outside of CDK.
84
+ */
85
+ public static fromAliasArn ( scope : Construct , id : string , aliasArn : string ) : IAgentAlias {
86
+ class Import extends Resource implements IAgentAlias {
87
+ public readonly aliasArn = aliasArn ;
88
+ public readonly aliasId : string ;
89
+ public readonly agentId : string ;
90
+
91
+ constructor ( ) {
92
+ super ( scope , id ) ;
93
+ [ this . agentId , this . aliasId ] = this . parseArnComponents ( aliasArn ) ;
94
+ }
95
+
96
+ private parseArnComponents ( arn : string ) : [ string , string ] {
97
+ const resourceName = Arn . split ( arn , ArnFormat . SLASH_RESOURCE_SLASH_RESOURCE_NAME ) . resourceName ! ;
98
+ const [ agentId , aliasId ] = resourceName . split ( '/' ) ;
99
+ return [ agentId , aliasId ] ;
100
+ }
101
+ }
102
+ return new Import ( ) ;
103
+ }
104
+
105
+ // ------------------------------------------------------
106
+ // CDK-created Agent Alias
107
+ // ------------------------------------------------------
108
+ /**
109
+ * The unique identifier of the agent.
110
+ */
111
+ public readonly agentId : string ;
56
112
/**
57
113
* The unique identifier of the agent alias.
114
+ * @example `TCLCITFZTN`
58
115
*/
59
116
public readonly aliasId : string ;
60
117
/**
61
118
* The ARN of the agent alias.
119
+ * @example `arn:aws:bedrock:us-east-1:123456789012:agent-alias/DNCJJYQKSU/TCLCITFZTN`
62
120
*/
63
121
public readonly aliasArn : string ;
64
122
/**
@@ -84,6 +142,7 @@ export class AgentAlias extends Construct {
84
142
} ] ;
85
143
}
86
144
145
+ this . agentId = props . agentId ;
87
146
this . aliasId = alias . attrAgentAliasId ;
88
147
this . aliasArn = alias . attrAgentAliasArn ;
89
148
this . aliasName = props . aliasName ?? 'latest' ;
0 commit comments