@aws/nx-plugin 0.60.2 → 0.62.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.
- package/LICENSE-THIRD-PARTY +678 -2016
- package/package.json +11 -11
- package/src/infra/app/__snapshots__/generator.spec.ts.snap +27 -33
- package/src/preset/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/py/fast-api/__snapshots__/generator.spec.ts.snap +13 -11
- package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +88 -418
- package/src/py/strands-agent/__snapshots__/generator.spec.ts.snap +88 -414
- package/src/smithy/ts/api/__snapshots__/generator.spec.ts.snap +14 -12
- package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +13 -11
- package/src/ts/lib/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/ts/lib/eslint.js +1 -1
- package/src/ts/lib/eslint.js.map +1 -1
- package/src/ts/lib/generator.js +13 -1
- package/src/ts/lib/generator.js.map +1 -1
- package/src/ts/lib/vitest.js +3 -3
- package/src/ts/lib/vitest.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +86 -416
- package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +1 -1
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +112 -94
- package/src/ts/react-website/app/files/app/src/components/AppLayout/index.tsx.template +5 -2
- package/src/ts/react-website/app/generator.js +1 -1
- package/src/ts/react-website/app/generator.js.map +1 -1
- package/src/utils/agent-core-constructs/agent-core-constructs.js +3 -4
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +23 -19
- package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +5 -3
- package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +53 -222
- package/src/utils/api-constructs/files/cdk/app/apis/rest/__apiNameKebabCase__.ts.template +13 -16
- package/src/utils/versions.d.ts +52 -51
- package/src/utils/versions.js +51 -50
- package/src/utils/versions.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/core/agent-core/runtime.ts.template +0 -159
|
@@ -1,42 +1,46 @@
|
|
|
1
1
|
import { Lazy, Names } from 'aws-cdk-lib';
|
|
2
|
-
import {
|
|
2
|
+
import { Platform } from 'aws-cdk-lib/aws-ecr-assets';
|
|
3
3
|
import { Construct } from 'constructs';
|
|
4
4
|
import { execSync } from 'child_process';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import * as url from 'url';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
AgentRuntimeArtifact,
|
|
9
|
+
ProtocolType,
|
|
10
|
+
Runtime,
|
|
11
|
+
RuntimeProps,
|
|
12
|
+
} from '@aws-cdk/aws-bedrock-agentcore-alpha';
|
|
11
13
|
|
|
12
14
|
export type <%- nameClassName %>Props = Omit<
|
|
13
|
-
|
|
14
|
-
'runtimeName' | '
|
|
15
|
+
RuntimeProps,
|
|
16
|
+
'runtimeName' | 'protocolConfiguration' | 'agentRuntimeArtifact'
|
|
15
17
|
>;
|
|
16
18
|
|
|
17
19
|
export class <%- nameClassName %> extends Construct {
|
|
18
|
-
public readonly dockerImage:
|
|
19
|
-
public readonly agentCoreRuntime:
|
|
20
|
+
public readonly dockerImage: AgentRuntimeArtifact;
|
|
21
|
+
public readonly agentCoreRuntime: Runtime;
|
|
20
22
|
|
|
21
23
|
constructor(scope: Construct, id: string, props?: <%- nameClassName %>Props) {
|
|
22
24
|
super(scope, id);
|
|
23
25
|
|
|
24
|
-
this.dockerImage =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
this.dockerImage = AgentRuntimeArtifact.fromAsset(
|
|
27
|
+
path.dirname(url.fileURLToPath(new URL(import.meta.url))),
|
|
28
|
+
{
|
|
29
|
+
platform: Platform.LINUX_ARM64,
|
|
30
|
+
extraHash: execSync(
|
|
31
|
+
`docker inspect <%- dockerImageTag %> --format '{{.Id}}'`,
|
|
32
|
+
{ encoding: 'utf-8' },
|
|
33
|
+
).trim(),
|
|
34
|
+
},
|
|
35
|
+
);
|
|
32
36
|
|
|
33
|
-
this.agentCoreRuntime = new
|
|
37
|
+
this.agentCoreRuntime = new Runtime(this, '<%- nameClassName %>', {
|
|
34
38
|
runtimeName: Lazy.string({
|
|
35
39
|
produce: () =>
|
|
36
40
|
Names.uniqueResourceName(this.agentCoreRuntime, { maxLength: 40 }),
|
|
37
41
|
}),
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
protocolConfiguration: ProtocolType.<%- serverProtocol %>,
|
|
43
|
+
agentRuntimeArtifact: this.dockerImage,
|
|
40
44
|
...props,
|
|
41
45
|
});
|
|
42
46
|
}
|
|
@@ -25,9 +25,11 @@ module "agent_core_runtime" {
|
|
|
25
25
|
agent_runtime_name = "<%= nameClassName %>"
|
|
26
26
|
docker_image_tag = "<%= dockerImageTag %>"
|
|
27
27
|
server_protocol = "<%= serverProtocol %>"
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
28
|
+
# authorizer_configuration = {
|
|
29
|
+
# custom_jwt_authorizer = {
|
|
30
|
+
# discovery_url = "https://xxx/.well-known/openid-configuration"
|
|
31
|
+
# allowed_clients = [ "xxx" ]
|
|
32
|
+
# }
|
|
31
33
|
# }
|
|
32
34
|
|
|
33
35
|
env = var.env
|
|
@@ -4,16 +4,12 @@ terraform {
|
|
|
4
4
|
required_providers {
|
|
5
5
|
aws = {
|
|
6
6
|
source = "hashicorp/aws"
|
|
7
|
-
version = ">= 6.
|
|
7
|
+
version = ">= 6.23"
|
|
8
8
|
}
|
|
9
9
|
null = {
|
|
10
10
|
source = "hashicorp/null"
|
|
11
11
|
version = ">= 3.0"
|
|
12
12
|
}
|
|
13
|
-
local = {
|
|
14
|
-
source = "hashicorp/local"
|
|
15
|
-
version = ">= 2.0"
|
|
16
|
-
}
|
|
17
13
|
random = {
|
|
18
14
|
source = "hashicorp/random"
|
|
19
15
|
version = ">= 3.0"
|
|
@@ -32,20 +28,23 @@ variable "agent_runtime_name" {
|
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
variable "server_protocol" {
|
|
35
|
-
description = "
|
|
31
|
+
description = "Server protocol for the agent runtime (HTTP, MCP, or A2A)"
|
|
36
32
|
type = string
|
|
33
|
+
default = "HTTP"
|
|
37
34
|
validation {
|
|
38
|
-
condition = contains(["MCP", "HTTP"], var.server_protocol)
|
|
39
|
-
error_message = "Protocol type must be either 'MCP' or '
|
|
35
|
+
condition = contains(["MCP", "HTTP", "A2A"], var.server_protocol)
|
|
36
|
+
error_message = "Protocol type must be either 'MCP', 'HTTP', or 'A2A'."
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
variable "
|
|
44
|
-
description = "
|
|
40
|
+
variable "authorizer_configuration" {
|
|
41
|
+
description = "Authorization configuration for authenticating incoming requests"
|
|
45
42
|
type = object({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
custom_jwt_authorizer = optional(object({
|
|
44
|
+
discovery_url = string
|
|
45
|
+
allowed_audience = optional(list(string))
|
|
46
|
+
allowed_clients = optional(list(string))
|
|
47
|
+
}))
|
|
49
48
|
})
|
|
50
49
|
default = null
|
|
51
50
|
}
|
|
@@ -83,7 +82,7 @@ data "aws_region" "current" {}
|
|
|
83
82
|
|
|
84
83
|
locals {
|
|
85
84
|
aws_account_id = data.aws_caller_identity.current.account_id
|
|
86
|
-
aws_region
|
|
85
|
+
aws_region = data.aws_region.current.id
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
# Random ID for bucket suffix to ensure uniqueness
|
|
@@ -94,7 +93,7 @@ resource "random_id" "unique_suffix" {
|
|
|
94
93
|
# ECR Repository
|
|
95
94
|
resource "aws_ecr_repository" "agent_core_repository" {
|
|
96
95
|
#checkov:skip=CKV_AWS_136:AES256 encryption is sufficient for ECR repositories
|
|
97
|
-
name
|
|
96
|
+
name = "${lower(var.agent_runtime_name)}_repository_${random_id.unique_suffix.hex}"
|
|
98
97
|
|
|
99
98
|
#checkov:skip=CKV_AWS_51:Image tag is reused for latest deployments
|
|
100
99
|
image_tag_mutability = "MUTABLE"
|
|
@@ -163,7 +162,7 @@ resource "aws_iam_role" "agent_core_runtime_role" {
|
|
|
163
162
|
tags = var.tags
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
# IAM Policy for
|
|
165
|
+
# IAM Policy for Agent Core Runtime
|
|
167
166
|
resource "aws_iam_policy" "agent_core_runtime_policy" {
|
|
168
167
|
name = "${var.agent_runtime_name}-QueryAgentPolicy-${random_id.unique_suffix.hex}"
|
|
169
168
|
description = "Restricted policy for Agent"
|
|
@@ -179,7 +178,7 @@ resource "aws_iam_policy" "agent_core_runtime_policy" {
|
|
|
179
178
|
"ecr:GetDownloadUrlForLayer"
|
|
180
179
|
]
|
|
181
180
|
Resource = [
|
|
182
|
-
|
|
181
|
+
aws_ecr_repository.agent_core_repository.arn
|
|
183
182
|
]
|
|
184
183
|
},
|
|
185
184
|
{
|
|
@@ -253,17 +252,6 @@ resource "aws_iam_policy" "agent_core_runtime_policy" {
|
|
|
253
252
|
"arn:aws:bedrock-agentcore:${local.aws_region}:${local.aws_account_id}:workload-identity-directory/default",
|
|
254
253
|
"arn:aws:bedrock-agentcore:${local.aws_region}:${local.aws_account_id}:workload-identity-directory/default/workload-identity/*"
|
|
255
254
|
]
|
|
256
|
-
},
|
|
257
|
-
{ "Sid" : "BedrockModelInvocation",
|
|
258
|
-
"Effect" : "Allow",
|
|
259
|
-
"Action" : [
|
|
260
|
-
"bedrock:InvokeModel",
|
|
261
|
-
"bedrock:InvokeModelWithResponseStream"
|
|
262
|
-
],
|
|
263
|
-
"Resource" : [
|
|
264
|
-
"arn:aws:bedrock:*::foundation-model/*",
|
|
265
|
-
"arn:aws:bedrock:${local.aws_region}:${local.aws_account_id}:*"
|
|
266
|
-
]
|
|
267
255
|
}
|
|
268
256
|
], var.additional_iam_policy_statements)
|
|
269
257
|
})
|
|
@@ -277,6 +265,7 @@ resource "aws_iam_role_policy_attachment" "agent_core_policy" {
|
|
|
277
265
|
policy_arn = aws_iam_policy.agent_core_runtime_policy.arn
|
|
278
266
|
}
|
|
279
267
|
|
|
268
|
+
# Data source to get Docker image digest
|
|
280
269
|
data "external" "docker_digest" {
|
|
281
270
|
program = ["sh", "-c", "echo '{\"digest\":\"'$(docker inspect ${var.docker_image_tag} --format '{{.Id}}')'\"}' "]
|
|
282
271
|
}
|
|
@@ -284,9 +273,7 @@ data "external" "docker_digest" {
|
|
|
284
273
|
# Null resource for Docker publish
|
|
285
274
|
resource "null_resource" "docker_publish" {
|
|
286
275
|
triggers = {
|
|
287
|
-
# Trigger rebuild when the image changes
|
|
288
276
|
docker_digest = data.external.docker_digest.result.digest
|
|
289
|
-
|
|
290
277
|
repository_url = aws_ecr_repository.agent_core_repository.repository_url
|
|
291
278
|
docker_image_tag = var.docker_image_tag
|
|
292
279
|
}
|
|
@@ -307,206 +294,45 @@ resource "null_resource" "docker_publish" {
|
|
|
307
294
|
depends_on = [aws_ecr_repository_policy.agent_core_ecr_policy]
|
|
308
295
|
}
|
|
309
296
|
|
|
310
|
-
#
|
|
311
|
-
resource "
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
config_hash = md5(join("", [jsonencode(var.customJWTAuthorizer), var.server_protocol]))
|
|
316
|
-
env_hash = md5(jsonencode(var.env))
|
|
317
|
-
}
|
|
297
|
+
# Bedrock AgentCore Agent Runtime
|
|
298
|
+
resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
|
|
299
|
+
agent_runtime_name = "${var.agent_runtime_name}_${random_id.unique_suffix.hex}"
|
|
300
|
+
description = "Agent Runtime for ${var.agent_runtime_name}"
|
|
301
|
+
role_arn = aws_iam_role.agent_core_runtime_role.arn
|
|
318
302
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
import json
|
|
324
|
-
import sys
|
|
325
|
-
|
|
326
|
-
# Create the client
|
|
327
|
-
client = boto3.client("bedrock-agentcore-control", region_name="${local.aws_region}")
|
|
328
|
-
|
|
329
|
-
# Environment variables for QueryAgentConfig
|
|
330
|
-
environment_variables = json.loads("""${jsonencode(var.env)}""")
|
|
331
|
-
agent_name = "${var.agent_runtime_name}_${random_id.unique_suffix.hex}"
|
|
332
|
-
authorization_config = json.loads("""{"customJWTAuthorizer": ${jsonencode(var.customJWTAuthorizer != null ? {
|
|
333
|
-
for k, v in var.customJWTAuthorizer : k => v if v != null
|
|
334
|
-
} : {})}}""")
|
|
335
|
-
|
|
336
|
-
try:
|
|
337
|
-
# First, check if an agent runtime with this name already exists
|
|
338
|
-
existing_agent_runtime_id = None
|
|
339
|
-
try:
|
|
340
|
-
list_response = client.list_agent_runtimes()
|
|
341
|
-
for runtime in list_response.get("agentRuntimes", []):
|
|
342
|
-
if runtime.get("agentRuntimeName") == agent_name:
|
|
343
|
-
existing_agent_runtime_id = runtime.get("agentRuntimeId")
|
|
344
|
-
print(f"Found existing agent runtime with ID: {existing_agent_runtime_id}")
|
|
345
|
-
break
|
|
346
|
-
except Exception as e:
|
|
347
|
-
print(f"Error listing agent runtimes: {e}")
|
|
348
|
-
|
|
349
|
-
if existing_agent_runtime_id:
|
|
350
|
-
# Update the existing agent runtime
|
|
351
|
-
try:
|
|
352
|
-
update_response = client.update_agent_runtime(
|
|
353
|
-
agentRuntimeId=existing_agent_runtime_id,
|
|
354
|
-
agentRuntimeArtifact={
|
|
355
|
-
"containerConfiguration": {
|
|
356
|
-
"containerUri": "${aws_ecr_repository.agent_core_repository.repository_url}:latest"
|
|
357
|
-
}
|
|
358
|
-
},
|
|
359
|
-
environmentVariables=environment_variables,
|
|
360
|
-
networkConfiguration={"networkMode": "PUBLIC"},
|
|
361
|
-
protocolConfiguration={"serverProtocol": "${var.server_protocol}"},
|
|
362
|
-
${var.customJWTAuthorizer == null ? "" : "authorizerConfiguration=authorization_config,"}
|
|
363
|
-
roleArn="${aws_iam_role.agent_core_runtime_role.arn}"
|
|
364
|
-
)
|
|
365
|
-
agent_runtime_id = existing_agent_runtime_id
|
|
366
|
-
print(f"Agent runtime updated successfully: {agent_runtime_id}")
|
|
367
|
-
except Exception as e:
|
|
368
|
-
print(f"Error updating agent runtime: {e}")
|
|
369
|
-
# If update fails, try to create a new one
|
|
370
|
-
existing_agent_runtime_id = None
|
|
371
|
-
|
|
372
|
-
if not existing_agent_runtime_id:
|
|
373
|
-
# Agent runtime doesn"t exist or update failed, create it
|
|
374
|
-
response = client.create_agent_runtime(
|
|
375
|
-
agentRuntimeName=agent_name,
|
|
376
|
-
agentRuntimeArtifact={
|
|
377
|
-
"containerConfiguration": {
|
|
378
|
-
"containerUri": "${aws_ecr_repository.agent_core_repository.repository_url}:latest"
|
|
379
|
-
}
|
|
380
|
-
},
|
|
381
|
-
environmentVariables=environment_variables,
|
|
382
|
-
networkConfiguration={"networkMode": "PUBLIC"},
|
|
383
|
-
protocolConfiguration={"serverProtocol": "${var.server_protocol}"},
|
|
384
|
-
${var.customJWTAuthorizer == null ? "" : "authorizerConfiguration=authorization_config,"}
|
|
385
|
-
roleArn="${aws_iam_role.agent_core_runtime_role.arn}"
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
agent_runtime_id = response.get("agentRuntimeId", "")
|
|
389
|
-
print(f"Agent runtime created successfully with ID: {agent_runtime_id}")
|
|
390
|
-
|
|
391
|
-
except Exception as e:
|
|
392
|
-
print(f"Error managing agent runtime: {str(e)}")
|
|
393
|
-
sys.exit(1)
|
|
394
|
-
'
|
|
395
|
-
EOT
|
|
303
|
+
agent_runtime_artifact {
|
|
304
|
+
container_configuration {
|
|
305
|
+
container_uri = "${aws_ecr_repository.agent_core_repository.repository_url}:latest"
|
|
306
|
+
}
|
|
396
307
|
}
|
|
397
308
|
|
|
398
|
-
|
|
399
|
-
null_resource.docker_publish,
|
|
400
|
-
aws_iam_role_policy_attachment.agent_core_policy
|
|
401
|
-
]
|
|
402
|
-
}
|
|
309
|
+
environment_variables = length(var.env) > 0 ? var.env : null
|
|
403
310
|
|
|
311
|
+
dynamic "authorizer_configuration" {
|
|
312
|
+
for_each = var.authorizer_configuration != null && var.authorizer_configuration.custom_jwt_authorizer != null ? [var.authorizer_configuration.custom_jwt_authorizer] : []
|
|
313
|
+
content {
|
|
314
|
+
custom_jwt_authorizer {
|
|
315
|
+
discovery_url = authorizer_configuration.value.discovery_url
|
|
316
|
+
allowed_audience = authorizer_configuration.value.allowed_audience
|
|
317
|
+
allowed_clients = authorizer_configuration.value.allowed_clients
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
404
321
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
triggers = {
|
|
408
|
-
aws_region = local.aws_region
|
|
409
|
-
agent_name = var.agent_runtime_name
|
|
410
|
-
unique_suffix = random_id.unique_suffix.hex
|
|
322
|
+
network_configuration {
|
|
323
|
+
network_mode = "PUBLIC"
|
|
411
324
|
}
|
|
412
325
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
command = <<-EOT
|
|
416
|
-
uv run --with boto3 python -c "
|
|
417
|
-
import boto3
|
|
418
|
-
import json
|
|
419
|
-
import os
|
|
420
|
-
|
|
421
|
-
# Create the client
|
|
422
|
-
client = boto3.client('bedrock-agentcore-control', region_name='${self.triggers.aws_region}')
|
|
423
|
-
|
|
424
|
-
agent_name = '${self.triggers.agent_name}_${self.triggers.unique_suffix}'
|
|
425
|
-
|
|
426
|
-
try:
|
|
427
|
-
# Find the agent runtime by name
|
|
428
|
-
agent_runtime_id = None
|
|
429
|
-
try:
|
|
430
|
-
list_response = client.list_agent_runtimes()
|
|
431
|
-
for runtime in list_response.get('agentRuntimes', []):
|
|
432
|
-
if runtime.get('agentRuntimeName') == agent_name:
|
|
433
|
-
agent_runtime_id = runtime.get('agentRuntimeId')
|
|
434
|
-
print(f'Found agent runtime to delete: {agent_name} (ID: {agent_runtime_id})')
|
|
435
|
-
break
|
|
436
|
-
except Exception as e:
|
|
437
|
-
print(f'Error listing agent runtimes: {e}')
|
|
438
|
-
|
|
439
|
-
if not agent_runtime_id:
|
|
440
|
-
print(f'No agent runtime found with name: {agent_name}')
|
|
441
|
-
exit(0)
|
|
442
|
-
|
|
443
|
-
# Delete the agent runtime using the found ID
|
|
444
|
-
response = client.delete_agent_runtime(
|
|
445
|
-
agentRuntimeId=agent_runtime_id
|
|
446
|
-
)
|
|
447
|
-
print(f'Agent runtime {agent_name} (ID: {agent_runtime_id}) deleted successfully:', json.dumps(response, indent=2, default=str))
|
|
448
|
-
|
|
449
|
-
except client.exceptions.ResourceNotFoundException:
|
|
450
|
-
print(f'Agent runtime {agent_name} not found, may have been already deleted')
|
|
451
|
-
except Exception as e:
|
|
452
|
-
print(f'Error deleting agent runtime {agent_name}:', str(e))
|
|
453
|
-
# Don't exit with error code during destroy to avoid blocking cleanup
|
|
454
|
-
"
|
|
455
|
-
EOT
|
|
326
|
+
protocol_configuration {
|
|
327
|
+
server_protocol = var.server_protocol
|
|
456
328
|
}
|
|
457
329
|
|
|
458
|
-
|
|
459
|
-
}
|
|
330
|
+
tags = var.tags
|
|
460
331
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
import boto3
|
|
465
|
-
import json
|
|
466
|
-
import sys
|
|
467
|
-
|
|
468
|
-
# Create the client
|
|
469
|
-
client = boto3.client("bedrock-agentcore-control", region_name="${local.aws_region}")
|
|
470
|
-
|
|
471
|
-
agent_name = "${var.agent_runtime_name}_${random_id.unique_suffix.hex}"
|
|
472
|
-
|
|
473
|
-
try:
|
|
474
|
-
# Find the agent runtime by name
|
|
475
|
-
list_response = client.list_agent_runtimes()
|
|
476
|
-
for runtime in list_response.get("agentRuntimes", []):
|
|
477
|
-
if runtime.get("agentRuntimeName") == agent_name:
|
|
478
|
-
agent_runtime_id = runtime.get("agentRuntimeId")
|
|
479
|
-
runtime_arn = f"arn:aws:bedrock-agentcore:${local.aws_region}:${local.aws_account_id}:runtime/{agent_runtime_id}"
|
|
480
|
-
|
|
481
|
-
result = {
|
|
482
|
-
"agent_runtime_id": agent_runtime_id,
|
|
483
|
-
"agent_runtime_arn": runtime_arn,
|
|
484
|
-
"agent_name": agent_name
|
|
485
|
-
}
|
|
486
|
-
print(json.dumps(result))
|
|
487
|
-
sys.exit(0)
|
|
488
|
-
|
|
489
|
-
# If not found, return empty values
|
|
490
|
-
result = {
|
|
491
|
-
"agent_runtime_id": "",
|
|
492
|
-
"agent_runtime_arn": "",
|
|
493
|
-
"agent_name": agent_name
|
|
494
|
-
}
|
|
495
|
-
print(json.dumps(result))
|
|
496
|
-
|
|
497
|
-
except Exception as e:
|
|
498
|
-
print(f"Error looking up agent runtime: {str(e)}", file=sys.stderr)
|
|
499
|
-
# Return empty values on error to avoid breaking Terraform
|
|
500
|
-
result = {
|
|
501
|
-
"agent_runtime_id": "",
|
|
502
|
-
"agent_runtime_arn": "",
|
|
503
|
-
"agent_name": agent_name
|
|
504
|
-
}
|
|
505
|
-
print(json.dumps(result))
|
|
506
|
-
EOT
|
|
332
|
+
depends_on = [
|
|
333
|
+
null_resource.docker_publish,
|
|
334
|
+
aws_iam_role_policy.agent_core_runtime_policy
|
|
507
335
|
]
|
|
508
|
-
|
|
509
|
-
depends_on = [null_resource.agent_core_runtime_deployment]
|
|
510
336
|
}
|
|
511
337
|
|
|
512
338
|
# Outputs
|
|
@@ -522,15 +348,20 @@ output "agent_core_runtime_role_name" {
|
|
|
522
348
|
|
|
523
349
|
output "agent_runtime_name" {
|
|
524
350
|
description = "Name of the deployed agent runtime"
|
|
525
|
-
value =
|
|
351
|
+
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_name
|
|
526
352
|
}
|
|
527
353
|
|
|
528
354
|
output "agent_core_runtime_arn" {
|
|
529
355
|
description = "ARN of the Bedrock Agent Core runtime"
|
|
530
|
-
value =
|
|
356
|
+
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_arn
|
|
531
357
|
}
|
|
532
358
|
|
|
533
359
|
output "agent_runtime_id" {
|
|
534
360
|
description = "ID of the Bedrock Agent Core runtime"
|
|
535
|
-
value =
|
|
361
|
+
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_id
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
output "agent_runtime_version" {
|
|
365
|
+
description = "Version of the Bedrock Agent Core runtime"
|
|
366
|
+
value = aws_bedrockagentcore_agent_runtime.agent_runtime.agent_runtime_version
|
|
536
367
|
}
|
|
@@ -15,19 +15,13 @@ import {
|
|
|
15
15
|
CognitoUserPoolsAuthorizer,
|
|
16
16
|
<%_ } _%>
|
|
17
17
|
} from 'aws-cdk-lib/aws-apigateway';
|
|
18
|
-
import {
|
|
19
|
-
Duration,
|
|
20
|
-
<%_ if (auth === 'IAM') { _%>
|
|
21
|
-
Stack,
|
|
22
|
-
<%_ } _%>
|
|
23
|
-
} from 'aws-cdk-lib';
|
|
18
|
+
import { Duration } from 'aws-cdk-lib';
|
|
24
19
|
import {
|
|
25
20
|
PolicyDocument,
|
|
26
21
|
PolicyStatement,
|
|
27
22
|
Effect,
|
|
28
23
|
AnyPrincipal,
|
|
29
24
|
<%_ if (auth === 'IAM') { _%>
|
|
30
|
-
AccountPrincipal,
|
|
31
25
|
IGrantable,
|
|
32
26
|
Grant,
|
|
33
27
|
<%_ } _%>
|
|
@@ -163,15 +157,6 @@ export class <%= apiNameClassName %><
|
|
|
163
157
|
policy: new PolicyDocument({
|
|
164
158
|
statements: [
|
|
165
159
|
<%_ if (auth === 'IAM') { _%>
|
|
166
|
-
// Here we grant any AWS credentials from the account that the project is deployed in to call the api.
|
|
167
|
-
// Machine to machine fine-grained access can be defined here using more specific principals (eg roles or
|
|
168
|
-
// users) and resources (eg which api paths may be invoked by which principal) if required.
|
|
169
|
-
new PolicyStatement({
|
|
170
|
-
effect: Effect.ALLOW,
|
|
171
|
-
principals: [new AccountPrincipal(Stack.of(scope).account)],
|
|
172
|
-
actions: ['execute-api:Invoke'],
|
|
173
|
-
resources: ['execute-api:/*'],
|
|
174
|
-
}),
|
|
175
160
|
// Open up OPTIONS to allow browsers to make unauthenticated preflight requests
|
|
176
161
|
new PolicyStatement({
|
|
177
162
|
effect: Effect.ALLOW,
|
|
@@ -206,6 +191,18 @@ export class <%= apiNameClassName %><
|
|
|
206
191
|
* @param grantee - The IAM principal to grant permissions to
|
|
207
192
|
*/
|
|
208
193
|
public grantInvokeAccess(grantee: IGrantable) {
|
|
194
|
+
// Here we grant grantee permission to call the api.
|
|
195
|
+
// Machine to machine fine-grained access can be defined here using more specific principals (eg roles or
|
|
196
|
+
// users) and resources (eg which api paths may be invoked by which principal) if required.
|
|
197
|
+
this.api.addToResourcePolicy(
|
|
198
|
+
new PolicyStatement({
|
|
199
|
+
effect: Effect.ALLOW,
|
|
200
|
+
principals: [grantee.grantPrincipal],
|
|
201
|
+
actions: ['execute-api:Invoke'],
|
|
202
|
+
resources: ['execute-api:/*'],
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
205
|
+
|
|
209
206
|
Grant.addToPrincipal({
|
|
210
207
|
grantee,
|
|
211
208
|
actions: ['execute-api:Invoke'],
|