@aws/nx-plugin 0.60.2 → 0.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,159 +0,0 @@
1
- import {
2
- Role,
3
- ServicePrincipal,
4
- PolicyStatement,
5
- Effect,
6
- PolicyDocument,
7
- IGrantable,
8
- Grant,
9
- IPrincipal,
10
- } from 'aws-cdk-lib/aws-iam';
11
- import { Construct } from 'constructs';
12
- import { Stack } from 'aws-cdk-lib';
13
- import { CfnRuntime } from 'aws-cdk-lib/aws-bedrockagentcore';
14
-
15
- /**
16
- * Options for the AgentCoreRuntime construct
17
- */
18
- export interface AgentCoreRuntimeProps {
19
- runtimeName: string;
20
- description?: string;
21
- containerUri: string;
22
- serverProtocol: 'MCP' | 'HTTP';
23
- environment?: Record<string, string>;
24
- authorizerConfiguration?: CfnRuntime.AuthorizerConfigurationProperty;
25
- }
26
-
27
- /**
28
- * A construct for creating a Bedrock AgentCore Runtime
29
- */
30
- export class AgentCoreRuntime extends Construct implements IGrantable {
31
- public readonly role: Role;
32
- public readonly arn: string;
33
-
34
- public readonly grantPrincipal: IPrincipal;
35
-
36
- constructor(scope: Construct, id: string, props: AgentCoreRuntimeProps) {
37
- super(scope, id);
38
-
39
- const region = Stack.of(this).region;
40
- const accountId = Stack.of(this).account;
41
-
42
- this.role = new Role(this, 'AgentCoreRole', {
43
- assumedBy: new ServicePrincipal('bedrock-agentcore.amazonaws.com'),
44
- inlinePolicies: {
45
- AgentCorePolicy: new PolicyDocument({
46
- statements: [
47
- new PolicyStatement({
48
- sid: 'ECRImageAccess',
49
- effect: Effect.ALLOW,
50
- actions: ['ecr:BatchGetImage', 'ecr:GetDownloadUrlForLayer'],
51
- resources: [`arn:aws:ecr:${region}:${accountId}:repository/*`],
52
- }),
53
- new PolicyStatement({
54
- effect: Effect.ALLOW,
55
- actions: ['logs:DescribeLogStreams', 'logs:CreateLogGroup'],
56
- resources: [
57
- `arn:aws:logs:${region}:${accountId}:log-group:/aws/bedrock-agentcore/runtimes/*`,
58
- ],
59
- }),
60
- new PolicyStatement({
61
- effect: Effect.ALLOW,
62
- actions: ['logs:DescribeLogGroups'],
63
- resources: [`arn:aws:logs:${region}:${accountId}:log-group:*`],
64
- }),
65
- new PolicyStatement({
66
- effect: Effect.ALLOW,
67
- actions: ['logs:CreateLogStream', 'logs:PutLogEvents'],
68
- resources: [
69
- `arn:aws:logs:${region}:${accountId}:log-group:/aws/bedrock-agentcore/runtimes/*:log-stream:*`,
70
- ],
71
- }),
72
- new PolicyStatement({
73
- sid: 'ECRTokenAccess',
74
- effect: Effect.ALLOW,
75
- actions: ['ecr:GetAuthorizationToken'],
76
- resources: ['*'],
77
- }),
78
- new PolicyStatement({
79
- effect: Effect.ALLOW,
80
- actions: [
81
- 'xray:PutTraceSegments',
82
- 'xray:PutTelemetryRecords',
83
- 'xray:GetSamplingRules',
84
- 'xray:GetSamplingTargets',
85
- ],
86
- resources: ['*'],
87
- }),
88
- new PolicyStatement({
89
- effect: Effect.ALLOW,
90
- actions: ['cloudwatch:PutMetricData'],
91
- resources: ['*'],
92
- conditions: {
93
- StringEquals: {
94
- 'cloudwatch:namespace': 'bedrock-agentcore',
95
- },
96
- },
97
- }),
98
- new PolicyStatement({
99
- sid: 'GetAgentAccessToken',
100
- effect: Effect.ALLOW,
101
- actions: [
102
- 'bedrock-agentcore:GetWorkloadAccessToken',
103
- 'bedrock-agentcore:GetWorkloadAccessTokenForJWT',
104
- 'bedrock-agentcore:GetWorkloadAccessTokenForUserId',
105
- ],
106
- resources: [
107
- `arn:aws:bedrock-agentcore:${region}:${accountId}:workload-identity-directory/default`,
108
- `arn:aws:bedrock-agentcore:${region}:${accountId}:workload-identity-directory/default/workload-identity/*`,
109
- ],
110
- }),
111
- new PolicyStatement({
112
- sid: 'BedrockModelInvocation',
113
- effect: Effect.ALLOW,
114
- actions: [
115
- 'bedrock:InvokeModel',
116
- 'bedrock:InvokeModelWithResponseStream',
117
- ],
118
- resources: [
119
- 'arn:aws:bedrock:*::foundation-model/*',
120
- `arn:aws:bedrock:${region}:${accountId}:*`,
121
- ],
122
- }),
123
- ],
124
- }),
125
- },
126
- });
127
- this.grantPrincipal = this.role.grantPrincipal;
128
-
129
- const agentRuntime = new CfnRuntime(this, 'MCPServerRuntime', {
130
- agentRuntimeName: props.runtimeName,
131
- agentRuntimeArtifact: {
132
- containerConfiguration: {
133
- containerUri: props.containerUri,
134
- },
135
- },
136
- description: props.description,
137
- environmentVariables: props.environment,
138
- networkConfiguration: {
139
- networkMode: 'PUBLIC',
140
- },
141
- protocolConfiguration: props.serverProtocol,
142
- roleArn: this.role.roleArn,
143
- authorizerConfiguration: props.authorizerConfiguration,
144
- });
145
-
146
- this.arn = agentRuntime.attrAgentRuntimeArn;
147
- }
148
-
149
- /**
150
- * Grant permissions to invoke the agent runtime (if using IAM auth - not required for JWT auth)
151
- */
152
- public grantInvoke = (grantee: IGrantable) => {
153
- Grant.addToPrincipal({
154
- grantee,
155
- actions: ['bedrock-agentcore:InvokeAgentRuntime'],
156
- resourceArns: [this.arn, `${this.arn}/*`],
157
- });
158
- };
159
- }