@aws/nx-plugin-mcp 0.119.0 → 0.121.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/bin/aws-nx-mcp.js +23 -35
- package/docs/guides/astro-docs.mdx +142 -0
- package/docs/guides/connection/py-agent-a2a.mdx +105 -0
- package/docs/guides/connection/py-agent-mcp.mdx +147 -0
- package/docs/guides/connection/react-agui.mdx +240 -0
- package/docs/guides/connection/react-fastapi.mdx +1476 -0
- package/docs/guides/connection/react-py-agent.mdx +198 -0
- package/docs/guides/connection/react-smithy.mdx +1355 -0
- package/docs/guides/connection/react-trpc.mdx +447 -0
- package/docs/guides/connection/react-ts-agent.mdx +198 -0
- package/docs/guides/connection/smithy-rdb.mdx +161 -0
- package/docs/guides/connection/trpc-rdb.mdx +127 -0
- package/docs/guides/connection/ts-agent-a2a.mdx +106 -0
- package/docs/guides/connection/ts-agent-mcp.mdx +144 -0
- package/docs/guides/connection/ts-agent-rdb.mdx +141 -0
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +135 -0
- package/docs/guides/connection.mdx +126 -0
- package/docs/guides/docker-bundling.mdx +403 -0
- package/docs/guides/fastapi.mdx +509 -0
- package/docs/guides/license.mdx +293 -0
- package/docs/guides/nx-generator.mdx +588 -0
- package/docs/guides/py-agent.mdx +483 -0
- package/docs/guides/py-mcp-server.mdx +161 -0
- package/docs/guides/python-lambda-function.mdx +207 -0
- package/docs/guides/python-project.mdx +228 -0
- package/docs/guides/react-website-auth.mdx +216 -0
- package/docs/guides/react-website.mdx +421 -0
- package/docs/guides/runtime-config.mdx +312 -0
- package/docs/guides/terraform-project.mdx +317 -0
- package/docs/guides/trpc.mdx +816 -0
- package/docs/guides/ts-agent.mdx +436 -0
- package/docs/guides/ts-lambda-function.mdx +218 -0
- package/docs/guides/ts-mcp-server.mdx +169 -0
- package/docs/guides/ts-nx-plugin.mdx +159 -0
- package/docs/guides/ts-rdb.mdx +759 -0
- package/docs/guides/ts-smithy-api.mdx +661 -0
- package/docs/guides/typescript-infrastructure.mdx +408 -0
- package/docs/guides/typescript-project.mdx +312 -0
- package/docs/guides/workspace.mdx +181 -0
- package/docs/snippets/agent/architecture.mdx +72 -0
- package/docs/snippets/agent/bedrock-deployment.mdx +172 -0
- package/docs/snippets/agent/runtime-arn.mdx +64 -0
- package/docs/snippets/api/api-architecture.mdx +93 -0
- package/docs/snippets/api/api-choice-note.mdx +6 -0
- package/docs/snippets/api/cors-configuration-cdk-note.mdx +25 -0
- package/docs/snippets/api/cors-configuration-terraform-note.mdx +28 -0
- package/docs/snippets/api/shared-constructs.mdx +38 -0
- package/docs/snippets/api/type-safe-api-integrations.mdx +643 -0
- package/docs/snippets/api/waf-configuration.mdx +37 -0
- package/docs/snippets/connection/a2a-infrastructure.mdx +63 -0
- package/docs/snippets/connection/lambda-rdb-ssl-requirements.mdx +40 -0
- package/docs/snippets/connection/mcp-server-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/connection/rdb-api-infrastructure.mdx +72 -0
- package/docs/snippets/connection/react-agent-infrastructure.mdx +61 -0
- package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +35 -0
- package/docs/snippets/lambda-function/architecture.mdx +36 -0
- package/docs/snippets/lambda-function/deploying-your-function.mdx +118 -0
- package/docs/snippets/mcp/architecture.mdx +58 -0
- package/docs/snippets/mcp/assistant-docs.mdx +10 -0
- package/docs/snippets/mcp/bedrock-deployment.mdx +167 -0
- package/docs/snippets/mcp/config.mdx +13 -0
- package/docs/snippets/mcp/configuration-py.mdx +42 -0
- package/docs/snippets/mcp/configuration-ts.mdx +53 -0
- package/docs/snippets/mcp/observability.mdx +8 -0
- package/docs/snippets/mcp/shared-constructs.mdx +32 -0
- package/docs/snippets/pdk-migration/example/01-migrate-api.mdx +602 -0
- package/docs/snippets/pdk-migration/example/02-migrate-website.mdx +915 -0
- package/docs/snippets/pdk-migration/example/03-migrate-infra.mdx +161 -0
- package/docs/snippets/pdk-migration/example/04-deploy.mdx +229 -0
- package/docs/snippets/pdk-migration/faq/aws-arch.mdx +17 -0
- package/docs/snippets/pdk-migration/faq/cdk-graph.mdx +29 -0
- package/docs/snippets/pdk-migration/faq/infrastructure-python-java.mdx +19 -0
- package/docs/snippets/pdk-migration/faq/pdk-nag.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/pipeline.mdx +15 -0
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +310 -0
- package/docs/snippets/pdk-migration/faq/use-of-projen.mdx +15 -0
- package/docs/snippets/prerequisites.mdx +20 -0
- package/docs/snippets/required-prerequisites.mdx +12 -0
- package/docs/snippets/shared-constructs.mdx +40 -0
- package/docs/snippets/tools/acurl.mdx +73 -0
- package/docs/snippets/ts-bundle.mdx +14 -0
- package/package.json +1 -1
- package/src/py/agent/schema.json +1 -1
- package/src/py/fast-api/schema.json +2 -2
- package/src/py/mcp-server/schema.json +1 -1
- package/src/smithy/ts/api/schema.json +2 -2
- package/src/trpc/backend/schema.json +2 -2
- package/src/ts/agent/schema.json +1 -1
- package/src/ts/mcp-server/schema.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Agent Bedrock Deployment
|
|
3
|
+
---
|
|
4
|
+
import Link from '@components/link.astro';
|
|
5
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
6
|
+
|
|
7
|
+
### Infrastructure as Code
|
|
8
|
+
|
|
9
|
+
If you selected `BedrockAgentCoreRuntime` for `computeType`, the relevant CDK or Terraform infrastructure is generated which you can use to deploy your Agent to [Amazon Bedrock AgentCore Runtime](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agents-tools-runtime.html).
|
|
10
|
+
|
|
11
|
+
<Infrastructure>
|
|
12
|
+
<Fragment slot="cdk">
|
|
13
|
+
A CDK construct is generated for your agent, named based on the `name` you chose when running the generator, or `<ProjectName>Agent` by default.
|
|
14
|
+
|
|
15
|
+
You can use this CDK construct in a CDK application:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { MyProjectAgent } from ':my-scope/common-constructs';
|
|
19
|
+
|
|
20
|
+
export class ExampleStack extends Stack {
|
|
21
|
+
constructor(scope: Construct, id: string) {
|
|
22
|
+
new MyProjectAgent(this, 'MyProjectAgent');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
:::note[CDK Construct]
|
|
28
|
+
This construct uses the [`aws-cdk-lib/aws-bedrockagentcore` module](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore-readme.html).
|
|
29
|
+
:::
|
|
30
|
+
</Fragment>
|
|
31
|
+
<Fragment slot="terraform">
|
|
32
|
+
A Terraform module is generated for you, named based on the `name` you chose when running the generator, or `<ProjectName>-agent` by default.
|
|
33
|
+
|
|
34
|
+
Pass the shared <Link path="/guides/runtime-config#writing-configuration">`runtime_config_appconfig`</Link> module's outputs into the agent module:
|
|
35
|
+
|
|
36
|
+
```terraform
|
|
37
|
+
module "my_project_agent" {
|
|
38
|
+
source = "../../common/terraform/src/app/agents/my-project-agent"
|
|
39
|
+
|
|
40
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
41
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
</Fragment>
|
|
45
|
+
</Infrastructure>
|
|
46
|
+
|
|
47
|
+
:::note[Bedrock Model Permissions]
|
|
48
|
+
The generated agent construct grants permission to invoke all Bedrock foundation models and inference profiles by default (`bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` on `arn:aws:bedrock:*:*:foundation-model/*` and `arn:aws:bedrock:*:*:inference-profile/*`).
|
|
49
|
+
|
|
50
|
+
You may wish to scope this down to the specific model(s) your agent uses. You can find the default model used by Strands agents in the [Strands documentation](https://strandsagents.com/latest/documentation/docs/user-guide/concepts/model-providers/amazon-bedrock/#default-model); see the [Strands model providers guide](https://strandsagents.com/latest/documentation/docs/user-guide/concepts/model-providers/) for configuring a different model.
|
|
51
|
+
:::
|
|
52
|
+
|
|
53
|
+
:::caution[Docker Required]
|
|
54
|
+
[Docker](https://www.docker.com/) is required to build and deploy your Agent. Make sure you have installed and launched Docker to avoid errors such as:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
ERROR: Cannot connect to the Docker daemon at unix://path/to/docker.sock.
|
|
58
|
+
```
|
|
59
|
+
:::
|
|
60
|
+
|
|
61
|
+
### Authentication
|
|
62
|
+
|
|
63
|
+
The generator provides an `auth` option to configure authentication for your Agent. You can choose between `IAM` (default) or `Cognito` authentication when generating your agent.
|
|
64
|
+
|
|
65
|
+
#### IAM
|
|
66
|
+
|
|
67
|
+
By default, your Agent will be secured using IAM authentication, simply deploy it without any arguments:
|
|
68
|
+
|
|
69
|
+
<Infrastructure>
|
|
70
|
+
<Fragment slot="cdk">
|
|
71
|
+
```ts {5}
|
|
72
|
+
import { MyProjectAgent } from ':my-scope/common-constructs';
|
|
73
|
+
|
|
74
|
+
export class ExampleStack extends Stack {
|
|
75
|
+
constructor(scope: Construct, id: string) {
|
|
76
|
+
new MyProjectAgent(this, 'MyProjectAgent');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
You can grant access to invoke your agent on Bedrock AgentCore Runtime using the `grantInvokeAccess` method, for example:
|
|
82
|
+
|
|
83
|
+
```ts {8}
|
|
84
|
+
import { MyProjectAgent } from ':my-scope/common-constructs';
|
|
85
|
+
|
|
86
|
+
export class ExampleStack extends Stack {
|
|
87
|
+
constructor(scope: Construct, id: string) {
|
|
88
|
+
const agent = new MyProjectAgent(this, 'MyProjectAgent');
|
|
89
|
+
const lambdaFunction = new Function(this, ...);
|
|
90
|
+
|
|
91
|
+
agent.grantInvokeAccess(lambdaFunction);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
</Fragment>
|
|
96
|
+
<Fragment slot="terraform">
|
|
97
|
+
```terraform {5-6}
|
|
98
|
+
# Agent
|
|
99
|
+
module "my_project_agent" {
|
|
100
|
+
# Relative path to the generated module in the common/terraform project
|
|
101
|
+
source = "../../common/terraform/src/app/agents/my-project-agent"
|
|
102
|
+
|
|
103
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
104
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To grant access to invoke your agent, you will need to add a policy such as the following, referencing the `module.my_project_agent.agent_core_runtime_arn` output:
|
|
109
|
+
|
|
110
|
+
```terraform
|
|
111
|
+
{
|
|
112
|
+
Effect = "Allow"
|
|
113
|
+
Action = [
|
|
114
|
+
"bedrock-agentcore:InvokeAgentRuntime"
|
|
115
|
+
]
|
|
116
|
+
Resource = [
|
|
117
|
+
module.my_project_agent.agent_core_runtime_arn,
|
|
118
|
+
"${module.my_project_agent.agent_core_runtime_arn}/*"
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
</Fragment>
|
|
123
|
+
</Infrastructure>
|
|
124
|
+
|
|
125
|
+
#### Cognito Authentication
|
|
126
|
+
|
|
127
|
+
When you select `Cognito` authentication, the generator configures the agent to use Cognito for authentication.
|
|
128
|
+
|
|
129
|
+
<Infrastructure>
|
|
130
|
+
<Fragment slot="cdk">
|
|
131
|
+
The generated construct accepts an `identity` prop which configures Cognito authentication:
|
|
132
|
+
|
|
133
|
+
```ts {8}
|
|
134
|
+
import { MyProjectAgent, UserIdentity } from ':my-scope/common-constructs';
|
|
135
|
+
|
|
136
|
+
export class ExampleStack extends Stack {
|
|
137
|
+
constructor(scope: Construct, id: string) {
|
|
138
|
+
const identity = new UserIdentity(this, 'Identity');
|
|
139
|
+
|
|
140
|
+
new MyProjectAgent(this, 'MyProjectAgent', {
|
|
141
|
+
identity,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
The `UserIdentity` construct can be generated using the <Link path="/guides/react-website-auth">`ts#react-website#auth` generator</Link>, or you can create your own CDK `UserPool` and `UserPoolClient`.
|
|
148
|
+
</Fragment>
|
|
149
|
+
<Fragment slot="terraform">
|
|
150
|
+
The generated module accepts `user_pool_id` and `user_pool_client_ids` variables for Cognito authentication:
|
|
151
|
+
|
|
152
|
+
```terraform {8-9}
|
|
153
|
+
module "user_identity" {
|
|
154
|
+
source = "../../common/terraform/src/core/user-identity"
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module "my_project_agent" {
|
|
158
|
+
source = "../../common/terraform/src/app/agents/my-project-agent"
|
|
159
|
+
|
|
160
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
161
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
162
|
+
|
|
163
|
+
user_pool_id = module.user_identity.user_pool_id
|
|
164
|
+
user_pool_client_ids = [module.user_identity.user_pool_client_id]
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
</Fragment>
|
|
168
|
+
</Infrastructure>
|
|
169
|
+
|
|
170
|
+
:::note[Custom OIDC Providers]
|
|
171
|
+
If you require custom JWT authentication with a non-Cognito OIDC provider, you can modify the generated CDK construct or Terraform module for your agent directly. Note that the connection generator will only support `IAM` or `Cognito` authentication.
|
|
172
|
+
:::
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Bedrock AgentCore Runtime ARN
|
|
3
|
+
---
|
|
4
|
+
import Link from '@components/link.astro';
|
|
5
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
6
|
+
|
|
7
|
+
To invoke your Agent deployed to Bedrock AgentCore Runtime, you can send a POST request to the Bedrock AgentCore Runtime dataplane endpoint with your URL-encoded runtime ARN.
|
|
8
|
+
|
|
9
|
+
You can obtain the runtime ARN from your infrastructure as follows:
|
|
10
|
+
|
|
11
|
+
<Infrastructure>
|
|
12
|
+
<Fragment slot="cdk">
|
|
13
|
+
```ts {9}
|
|
14
|
+
import { CfnOutput } from 'aws-cdk-lib';
|
|
15
|
+
import { MyProjectAgent } from ':my-scope/common-constructs';
|
|
16
|
+
|
|
17
|
+
export class ExampleStack extends Stack {
|
|
18
|
+
constructor(scope: Construct, id: string) {
|
|
19
|
+
const agent = new MyProjectAgent(this, 'MyProjectAgent');
|
|
20
|
+
|
|
21
|
+
new CfnOutput(this, 'AgentArn', {
|
|
22
|
+
value: agent.agentCoreRuntime.agentRuntimeArn,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
</Fragment>
|
|
28
|
+
<Fragment slot="terraform">
|
|
29
|
+
```terraform {5-6, 10}
|
|
30
|
+
# Agent
|
|
31
|
+
module "my_project_agent" {
|
|
32
|
+
# Relative path to the generated module in the common/terraform project
|
|
33
|
+
source = "../../common/terraform/src/app/agents/my-project-agent"
|
|
34
|
+
|
|
35
|
+
appconfig_application_id = module.runtime_config_appconfig.application_id
|
|
36
|
+
appconfig_application_arn = module.runtime_config_appconfig.application_arn
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
output "agent_arn" {
|
|
40
|
+
value = module.my_project_agent.agent_core_runtime_arn
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
</Fragment>
|
|
44
|
+
</Infrastructure>
|
|
45
|
+
|
|
46
|
+
The ARN will have the following format: `arn:aws:bedrock-agentcore:<region>:<account>:runtime/<agent-runtime-id>`.
|
|
47
|
+
|
|
48
|
+
You can then URL-encode the ARN by replacing `:` with `%3A` and `/` with `%2F`.
|
|
49
|
+
|
|
50
|
+
:::tip[Browser Console]
|
|
51
|
+
This is straightforward in a browser console or Node REPL using the built in `encodeURIComponent` method:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
encodeURIComponent('arn:aws:bedrock-agentcore:<region>:<account>:runtime/<agent-runtime-id>')
|
|
55
|
+
```
|
|
56
|
+
:::
|
|
57
|
+
|
|
58
|
+
The Bedrock AgentCore Runtime dataplane URL for invoking the agent is as follows:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
https://bedrock-agentcore.<region>.amazonaws.com/runtimes/<url-encoded-arn>/invocations
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The exact way to invoke this URL depends upon the authentication method used.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: API Architecture
|
|
3
|
+
---
|
|
4
|
+
import { Tabs, TabItem } from '@astrojs/starlight/components';
|
|
5
|
+
|
|
6
|
+
The deployed application has the following architecture:
|
|
7
|
+
|
|
8
|
+
<Tabs syncKey="http-rest">
|
|
9
|
+
<TabItem label="REST API" _filter={{ computeType: 'ServerlessApiGatewayRestApi' }}>
|
|
10
|
+
```d2 inline=true
|
|
11
|
+
direction: right
|
|
12
|
+
|
|
13
|
+
client: Client {
|
|
14
|
+
shape: image
|
|
15
|
+
icon: /nx-plugin-for-aws/icons/aws/client.svg
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
waf: WAF {
|
|
19
|
+
shape: image
|
|
20
|
+
icon: /nx-plugin-for-aws/icons/aws/waf.svg
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
apigw: API Gateway\n(REST API) {
|
|
24
|
+
shape: image
|
|
25
|
+
icon: /nx-plugin-for-aws/icons/aws/api-gateway.svg
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
lambda: Lambda {
|
|
29
|
+
shape: image
|
|
30
|
+
icon: /nx-plugin-for-aws/icons/aws/lambda.svg
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
cw: CloudWatch\n(Logs, Metrics) {
|
|
34
|
+
shape: image
|
|
35
|
+
icon: /nx-plugin-for-aws/icons/aws/cloudwatch.svg
|
|
36
|
+
near: top-right
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
xray: X-Ray\n(Traces) {
|
|
40
|
+
shape: image
|
|
41
|
+
icon: /nx-plugin-for-aws/icons/aws/xray.svg
|
|
42
|
+
near: bottom-right
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
client -> waf
|
|
46
|
+
waf -> apigw
|
|
47
|
+
apigw -> lambda
|
|
48
|
+
lambda -> cw
|
|
49
|
+
lambda -> xray
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
REST APIs include an [AWS WAFv2](https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html) Web ACL in front of the API Gateway stage with the AWS managed default ruleset enabled.
|
|
53
|
+
</TabItem>
|
|
54
|
+
<TabItem label="HTTP API" _filter={{ computeType: 'ServerlessApiGatewayHttpApi' }}>
|
|
55
|
+
```d2 inline=true
|
|
56
|
+
direction: right
|
|
57
|
+
|
|
58
|
+
client: Client {
|
|
59
|
+
shape: image
|
|
60
|
+
icon: /nx-plugin-for-aws/icons/aws/client.svg
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
apigw: API Gateway\n(HTTP API) {
|
|
64
|
+
shape: image
|
|
65
|
+
icon: /nx-plugin-for-aws/icons/aws/api-gateway.svg
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
lambda: Lambda {
|
|
69
|
+
shape: image
|
|
70
|
+
icon: /nx-plugin-for-aws/icons/aws/lambda.svg
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
cw: CloudWatch\n(Logs, Metrics) {
|
|
74
|
+
shape: image
|
|
75
|
+
icon: /nx-plugin-for-aws/icons/aws/cloudwatch.svg
|
|
76
|
+
near: top-right
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
xray: X-Ray\n(Traces) {
|
|
80
|
+
shape: image
|
|
81
|
+
icon: /nx-plugin-for-aws/icons/aws/xray.svg
|
|
82
|
+
near: bottom-right
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
client -> apigw
|
|
86
|
+
apigw -> lambda
|
|
87
|
+
lambda -> cw
|
|
88
|
+
lambda -> xray
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
HTTP APIs do not support WAF directly — if you need WAF protection, choose REST API instead or front the HTTP API with a CloudFront distribution.
|
|
92
|
+
</TabItem>
|
|
93
|
+
</Tabs>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Choose between REST and HTTP
|
|
3
|
+
---
|
|
4
|
+
:::note[API Type Choice]
|
|
5
|
+
You can choose between either a [REST API](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html) or [HTTP API](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) to deploy your API, please refer to the [API Gateway Developer Guide](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html) to help you decide.
|
|
6
|
+
:::
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CORS configuration CDK
|
|
3
|
+
---
|
|
4
|
+
import Link from '@components/link.astro';
|
|
5
|
+
|
|
6
|
+
:::note[CDK CORS Configuration]
|
|
7
|
+
If your solution includes a website you can configure its CloudFront distribution as the only permitted CORS origin in the API gateway / API AWS Lambda integrations for HTTP / REST APIs.
|
|
8
|
+
You can call the API `restrictCorsTo` method with website constructs, CloudFront distributions, origin strings, or a mix of them.
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { MyApi, MyWebsite } from ':my-scope/common-constructs';
|
|
12
|
+
|
|
13
|
+
export class ExampleStack extends Stack {
|
|
14
|
+
constructor(scope: Construct, id: string) {
|
|
15
|
+
const api = new MyApi(this, 'MyApi', {
|
|
16
|
+
integrations: MyApi.defaultIntegrations(this).build(),
|
|
17
|
+
});
|
|
18
|
+
const website = new MyWebsite(this, 'MyWebsite');
|
|
19
|
+
api.restrictCorsTo(website, 'http://localhost:4200');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The `MyWebsite` construct can be generated using the <Link path="/guides/react-website">`ts#react-website` generator</Link>
|
|
25
|
+
:::
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: CORS configuration Terraform
|
|
3
|
+
---
|
|
4
|
+
import Link from '@components/link.astro';
|
|
5
|
+
|
|
6
|
+
:::note[Terraform CORS Configuration]
|
|
7
|
+
If your solution includes a Terraform website module then you can use its CloudFront domain name to restrict CORS.
|
|
8
|
+
Given a CloudFront domain name `<domain_name>`, within the Terraform module for deploying your API add
|
|
9
|
+
- a `cors_allow_origins` property, set to `["http://localhost:4200", "http://localhost:4300", "https://<domain name>"]`, for HTTP APIs. This restricts the API gateway CORS to this distribution and local host.
|
|
10
|
+
- an `ALLOWED_ORIGINS` environment variable, set to `"https://<domain_name>"`, for REST APIs. This sets the CloudFront distribution as the only permitted CORS origin (other than local host) in AWS Lambda integrations. Note that this restriction is not applied to preflight OPTIONS - please +1 [this GitHub issue](https://github.com/awslabs/nx-plugin-for-aws/issues/377) to help prioritise addressing this.
|
|
11
|
+
|
|
12
|
+
```hcl {4,6,9}
|
|
13
|
+
module "my_api" {
|
|
14
|
+
source = "../../common/terraform/src/app/apis/my-api"
|
|
15
|
+
|
|
16
|
+
asset_bucket_name = module.asset_bucket.bucket_name
|
|
17
|
+
|
|
18
|
+
cors_allow_origins = ["http://localhost:4200", "http://localhost:4300", "https://<domain name>"] // Only required for HTTP API
|
|
19
|
+
|
|
20
|
+
env = {
|
|
21
|
+
ALLOWED_ORIGINS = "https://<domain name>" // Only required for REST API
|
|
22
|
+
ENVIRONMENT = var.environment
|
|
23
|
+
LOG_LEVEL = "INFO"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
The `MyWebsite` construct can be generated using the <Link path="/guides/react-website">`ts#react-website` generator</Link>
|
|
28
|
+
:::
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: API Shared Constructs
|
|
3
|
+
---
|
|
4
|
+
import { FileTree } from '@astrojs/starlight/components';
|
|
5
|
+
import Infrastructure from '@components/infrastructure.astro';
|
|
6
|
+
|
|
7
|
+
For deploying your API, the following files are generated:
|
|
8
|
+
|
|
9
|
+
<Infrastructure>
|
|
10
|
+
<Fragment slot="cdk">
|
|
11
|
+
<FileTree>
|
|
12
|
+
- packages/common/constructs/src
|
|
13
|
+
- app
|
|
14
|
+
- apis
|
|
15
|
+
- \<project-name>.ts CDK construct for deploying your API
|
|
16
|
+
- core
|
|
17
|
+
- api
|
|
18
|
+
- http-api.ts CDK construct for deploying an HTTP API (if you selected to deploy an HTTP API)
|
|
19
|
+
- rest-api.ts CDK construct for deploying a REST API (if you selected to deploy a REST API)
|
|
20
|
+
- utils.ts Utilities for the API constructs
|
|
21
|
+
</FileTree>
|
|
22
|
+
</Fragment>
|
|
23
|
+
<Fragment slot="terraform">
|
|
24
|
+
<FileTree>
|
|
25
|
+
- packages/common/terraform/src
|
|
26
|
+
- app
|
|
27
|
+
- apis
|
|
28
|
+
- \<project-name>
|
|
29
|
+
- \<project-name>.tf Module for deploying your API
|
|
30
|
+
- core
|
|
31
|
+
- api
|
|
32
|
+
- http-api
|
|
33
|
+
- http-api.tf Module for deploying an HTTP API (if you selected to deploy an HTTP API)
|
|
34
|
+
- rest-api
|
|
35
|
+
- rest-api.tf Module for deploying a REST API (if you selected to deploy a REST API)
|
|
36
|
+
</FileTree>
|
|
37
|
+
</Fragment>
|
|
38
|
+
</Infrastructure>
|