MCPcopy Create free account
hub / github.com/aws-samples/sample-devgenius-aws-solution-builder / constructor

Method constructor

lib/index.ts:104–910  ·  view source on GitHub ↗
(scope: Construct, id: string, props: cdk.StackProps)

Source from the content-addressed store, hash-verified

102 // ----------------------------------------------------------------- //
103 const gatewayServiceRole = new iam.Role(this, "GatewayServiceRole", {
104 roleName: `${stackName}-${region}-gateway-role`,
105 description: "Role assumed by the AgentCore Gateway to call web-search",
106 assumedBy: new iam.ServicePrincipal("bedrock-agentcore.amazonaws.com", {
107 conditions: {
108 StringEquals: { "aws:SourceAccount": account },
109 ArnLike: {
110 "aws:SourceArn": `arn:aws:bedrock-agentcore:${region}:${account}:gateway/*`,
111 },
112 },
113 }),
114 })
115 gatewayServiceRole.addToPolicy(
116 new iam.PolicyStatement({
117 sid: "InvokeGateway",
118 actions: ["bedrock-agentcore:InvokeGateway"],
119 resources: [`arn:aws:bedrock-agentcore:${region}:${account}:gateway/*`],
120 })
121 )
122 gatewayServiceRole.addToPolicy(
123 new iam.PolicyStatement({
124 sid: "InvokeWebSearch",
125 actions: ["bedrock-agentcore:InvokeWebSearch"],
126 resources: [`arn:aws:bedrock-agentcore:${region}:aws:tool/web-search.v1`],
127 })
128 )
129
130 const gateway = new cdk.CfnResource(this, "WebSearchGateway", {
131 type: "AWS::BedrockAgentCore::Gateway",
132 properties: {
133 Name: `${stackName}-websearch`.replace(/[^a-zA-Z0-9_-]/g, "-"),
134 Description: "DevGenius managed web-search gateway",
135 ProtocolType: "MCP",
136 AuthorizerType: "AWS_IAM",
137 RoleArn: gatewayServiceRole.roleArn,
138 },
139 })
140 const gatewayUrl = gateway.getAtt("GatewayUrl").toString()
141
142 const webSearchTarget = new cdk.CfnResource(this, "WebSearchTarget", {
143 type: "AWS::BedrockAgentCore::GatewayTarget",
144 properties: {
145 GatewayIdentifier: gateway.getAtt("GatewayIdentifier").toString(),
146 Name: "websearch",
147 Description: "Built-in web-search connector",
148 CredentialProviderConfigurations: [
149 { CredentialProviderType: "GATEWAY_IAM_ROLE" },
150 ],
151 TargetConfiguration: {
152 Mcp: {
153 Connector: {
154 Source: { ConnectorId: "web-search" },
155 Configurations: [{ Name: "WebSearch", ParameterValues: {} }],
156 },
157 },
158 },
159 },
160 })
161 webSearchTarget.addDependency(gateway)

Callers

nothing calls this directly

Calls 2

addTagsMethod · 0.95
addOutputsMethod · 0.95

Tested by

no test coverage detected