@aws/nx-plugin-mcp 1.5.0 → 1.6.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 +204 -64
- package/docs/get_started/tutorials/dungeon-game/4.mdx +5 -1
- package/docs/get_started/tutorials/dungeon-game/greengrass-dice.mdx +290 -0
- package/docs/get_started/tutorials/dungeon-game/wrap-up.mdx +66 -3
- package/docs/get_started/tutorials/greengrass/1.mdx +116 -0
- package/docs/get_started/tutorials/greengrass/2.mdx +198 -0
- package/docs/get_started/tutorials/greengrass/3.mdx +131 -0
- package/docs/get_started/tutorials/greengrass/cleanup.mdx +137 -0
- package/docs/get_started/tutorials/greengrass/overview.mdx +65 -0
- package/docs/guides/connection/ts-agent-rdb.mdx +1 -1
- package/docs/guides/connection/ts-mcp-server-rdb.mdx +1 -1
- package/docs/guides/greengrass-component.mdx +7 -1
- package/docs/guides/observability-langfuse.mdx +146 -0
- package/docs/guides/ts-rdb.mdx +7 -1
- package/docs/snippets/connection/strands-agent-rdb-ssl-requirements.mdx +3 -28
- package/docs/snippets/connection/ts-mcp-server-rdb-ssl-requirements.mdx +3 -28
- package/generators.json +8 -0
- package/package.json +1 -1
- package/src/observability/langfuse/schema.json +38 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Optional: roll dice with Greengrass"
|
|
3
|
+
description: Let the Dungeon Adventure Story Agent call a tool that requests a dice roll from a Greengrass core device and uses its result in the story.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Link from '@components/link.astro';
|
|
7
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
8
|
+
import PackageManagerShortCommand from '@components/package-manager-short-command.astro';
|
|
9
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
10
|
+
import InstallCommand from '@components/install-command.astro';
|
|
11
|
+
import E2ECode from '@components/e2e-code.astro';
|
|
12
|
+
import E2EDiff from '@components/e2e-diff.astro';
|
|
13
|
+
import { getDungeonDiceDependencies } from '../../../../../../../../e2e/src/utils';
|
|
14
|
+
|
|
15
|
+
Keep the dungeon you deployed in <Link path="get_started/tutorials/dungeon-game/4">Module 4</Link>.
|
|
16
|
+
Before destroying it, give its Story Agent a dice device:
|
|
17
|
+
|
|
18
|
+
> "I try to pick the lock. Roll a d20 to see whether I succeed."
|
|
19
|
+
|
|
20
|
+
The agent calls `roll-dice`. A Python component on a Greengrass core produces
|
|
21
|
+
the roll, and the MCP tool returns that device result to the agent. The reply
|
|
22
|
+
can then say "d20: 17" and describe the outcome.
|
|
23
|
+
|
|
24
|
+
This optional route uses an EC2 core with a software dice simulator. You can
|
|
25
|
+
later replace its random-number function with input from a physical dice tray.
|
|
26
|
+
The <Link path="get_started/tutorials/greengrass/overview">standalone Greengrass tutorial</Link>
|
|
27
|
+
remains a separate way to learn component generation from an empty workspace.
|
|
28
|
+
|
|
29
|
+
## What you will add
|
|
30
|
+
|
|
31
|
+
```d2
|
|
32
|
+
direction: right
|
|
33
|
+
player: Player
|
|
34
|
+
agent: Story Agent
|
|
35
|
+
tool: "Inventory MCP server\nroll-dice"
|
|
36
|
+
dice_shadow: "AWS IoT Core\nnamed shadow: dungeon-dice"
|
|
37
|
+
device: "Greengrass core\ncom.example.DungeonDice"
|
|
38
|
+
player -> agent: "Attempt an action"
|
|
39
|
+
agent -> tool: "roll-dice(sides=20)"
|
|
40
|
+
tool -> dice_shadow: "Desired request + request ID"
|
|
41
|
+
dice_shadow -> device: "MQTT delta through IPC"
|
|
42
|
+
device -> dice_shadow: "Reported result + same ID"
|
|
43
|
+
dice_shadow -> tool: "Correlated result"
|
|
44
|
+
tool -> agent: "d20 = 17"
|
|
45
|
+
agent -> player: "Result and consequence"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The cloud shadow holds one pending request and the most recent result. The
|
|
49
|
+
tool waits up to 12 seconds; it never generates a fallback roll. A version
|
|
50
|
+
check prevents concurrent callers from replacing an active request. The device
|
|
51
|
+
stores its last result before publishing, so MQTT redelivery and a component
|
|
52
|
+
restart do not reroll the same request.
|
|
53
|
+
|
|
54
|
+
This sandbox shares one dice device among players. A busy device returns an
|
|
55
|
+
error. It does not add a fleet-wide queue or associate personal devices with
|
|
56
|
+
Cognito users. Those are separate extensions for a multi-player product.
|
|
57
|
+
|
|
58
|
+
## 1. Provision a core without tearing down the dungeon
|
|
59
|
+
|
|
60
|
+
Use the same AWS account and Region as the deployed dungeon. Set the profile
|
|
61
|
+
explicitly; use a new prefix for the device resources:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
export TUTORIAL_AWS_PROFILE=<your-dungeon-profile>
|
|
65
|
+
export TUTORIAL_AWS_REGION=<your-dungeon-region>
|
|
66
|
+
export TUTORIAL_PREFIX=gg-dungeon-dice
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Follow <Link path="get_started/tutorials/greengrass/2">Provision the core device</Link>
|
|
70
|
+
from the **dungeon workspace**, including removal of the temporary installer
|
|
71
|
+
policy. That page creates the instance and writes `.greengrass-tutorial.env`.
|
|
72
|
+
Do not create another Nx workspace or run the standalone heartbeat modules.
|
|
73
|
+
The setup script's existing defaults stay unchanged.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
source .greengrass-tutorial.env
|
|
77
|
+
export DICE_IOT_ENDPOINT=$(aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
|
|
78
|
+
iot describe-endpoint --endpoint-type iot:Data-ATS --query endpointAddress --output text)
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Initialize the new device's named shadow once, before enabling the tool. Do not
|
|
82
|
+
run this reset against a device with an active dice request:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
|
|
86
|
+
iot-data update-thing-shadow --endpoint-url "https://${DICE_IOT_ENDPOINT}" \
|
|
87
|
+
--thing-name "$TUTORIAL_THING_NAME" --shadow-name dungeon-dice \
|
|
88
|
+
--cli-binary-format raw-in-base64-out \
|
|
89
|
+
--payload '{"state":{"desired":{"command":null},"reported":{"command":null,"result":null}}}' \
|
|
90
|
+
/tmp/dungeon-dice-shadow.json
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The EC2 walkthrough uses x86_64 Linux. A Raspberry Pi running 64-bit Linux uses
|
|
94
|
+
`linux-arm64` instead; both the generated recipe and native dependencies must
|
|
95
|
+
target that architecture. See <Link path="guides/greengrass-component#hardware-and-operating-systems">hardware support</Link>.
|
|
96
|
+
An ESP32 can supply sensor input to a gateway, but cannot run this Python component.
|
|
97
|
+
|
|
98
|
+
## 2. Generate the dice component
|
|
99
|
+
|
|
100
|
+
Create a separate Python host so the device artifact does not carry the Story
|
|
101
|
+
Agent's cloud dependencies:
|
|
102
|
+
|
|
103
|
+
<RunGenerator generator="py#project" requiredParameters={{ name: 'edge' }} noInteractive readonly />
|
|
104
|
+
<RunGenerator generator="greengrass#component" requiredParameters={{ project: 'edge', name: 'dice', language: 'python', componentName: 'com.example.DungeonDice', componentVersion: 'NEXT_PATCH', platform: 'linux-amd64', ipc: true, infra: 'component-version', iac: 'cdk' }} noInteractive readonly />
|
|
105
|
+
|
|
106
|
+
Replace `packages/edge/greengrass/dice/main.py`:
|
|
107
|
+
|
|
108
|
+
<E2ECode lang="python" path="dungeon-adventure/dice/main.py.template" />
|
|
109
|
+
|
|
110
|
+
Replace `packages/edge/greengrass/dice/recipe.yaml`:
|
|
111
|
+
|
|
112
|
+
<E2ECode lang="yaml" path="dungeon-adventure/dice/recipe.yaml.template" />
|
|
113
|
+
|
|
114
|
+
Replace **every** `REPLACE_WITH_CORE_THING_NAME` with the value of
|
|
115
|
+
`TUTORIAL_THING_NAME`. The recipe's IPC permissions name only this device's dice
|
|
116
|
+
shadow topics. Python writes `dice-result.json` in the component's writable
|
|
117
|
+
working directory, outside its read-only artifact directory.
|
|
118
|
+
|
|
119
|
+
Replace `packages/edge/tests/greengrass/test_dice.py`:
|
|
120
|
+
|
|
121
|
+
<E2ECode lang="python" path="dungeon-adventure/dice/test_dice.py.template" />
|
|
122
|
+
|
|
123
|
+
These tests exercise valid rolls, duplicates, restart recovery, stale requests,
|
|
124
|
+
expiry, and persistence failures. The default generator's heartbeat test is
|
|
125
|
+
replaced because the component now implements a different behavior.
|
|
126
|
+
|
|
127
|
+
## 3. Add the agent's dice tool
|
|
128
|
+
|
|
129
|
+
Add the IoT data-plane client to the Inventory MCP project:
|
|
130
|
+
|
|
131
|
+
<InstallCommand pkg={getDungeonDiceDependencies()} project="@dungeon-adventure/inventory" />
|
|
132
|
+
|
|
133
|
+
Create `packages/inventory/src/mcp-server/roll-dice.ts`:
|
|
134
|
+
|
|
135
|
+
<E2ECode lang="typescript" path="dungeon-adventure/dice/roll-dice.ts.template" />
|
|
136
|
+
|
|
137
|
+
Create `packages/inventory/src/mcp-server/register-dice.ts`:
|
|
138
|
+
|
|
139
|
+
<E2ECode lang="typescript" path="dungeon-adventure/dice/register-dice.ts.template" />
|
|
140
|
+
|
|
141
|
+
Update `packages/inventory/src/mcp-server/server.ts`:
|
|
142
|
+
|
|
143
|
+
<E2EDiff lang="typescript" before="dungeon-adventure/2/mcp/server.ts.template" after="dungeon-adventure/dice/server.ts.template" />
|
|
144
|
+
|
|
145
|
+
Keep all three inventory tools. The generated Story Agent connection already
|
|
146
|
+
discovers tools from this server, so it will also discover `roll-dice`.
|
|
147
|
+
The tool accepts only the die size. Device identity and endpoint come from the
|
|
148
|
+
server's configuration; the model cannot choose another device or MQTT topic.
|
|
149
|
+
During local development, inventory tools remain usable without the `DICE_*`
|
|
150
|
+
environment variables. Calling `roll-dice` returns an unconfigured-device
|
|
151
|
+
error until `DICE_THING_NAME`, `DICE_IOT_ENDPOINT` and `DICE_AWS_REGION` are set.
|
|
152
|
+
|
|
153
|
+
Update `packages/story/dungeon_adventure_story/agent/agent.py`:
|
|
154
|
+
|
|
155
|
+
<E2EDiff lang="python" before="dungeon-adventure/3/agent.py.template" after="dungeon-adventure/dice/agent.py.template" />
|
|
156
|
+
|
|
157
|
+
The replacement permits sequential calls so a successful roll can be followed
|
|
158
|
+
by an inventory update. It still allows only one roll per turn and explicitly
|
|
159
|
+
stops the challenge when the dice tool fails.
|
|
160
|
+
|
|
161
|
+
## 4. Compose the device resources into the existing application
|
|
162
|
+
|
|
163
|
+
Create `packages/infra/src/dice-resources.ts`:
|
|
164
|
+
|
|
165
|
+
<E2ECode lang="typescript" path="dungeon-adventure/dice/dice-resources.ts.template" />
|
|
166
|
+
|
|
167
|
+
Update `packages/infra/src/stacks/application-stack.ts` to pass the device
|
|
168
|
+
configuration to the MCP server and grant its runtime access to the shadow:
|
|
169
|
+
|
|
170
|
+
<E2EDiff lang="typescript" before="dungeon-adventure/2/stacks/application-stack.ts.template" after="dungeon-adventure/dice/application-stack.ts.template" />
|
|
171
|
+
|
|
172
|
+
Keep the rest of the existing application stack. `DiceResources` owns the
|
|
173
|
+
device parameters, artifact grant, component and its
|
|
174
|
+
deployment.
|
|
175
|
+
|
|
176
|
+
There are three permission boundaries:
|
|
177
|
+
|
|
178
|
+
- The core's existing IoT certificate policy permits publishing, subscribing
|
|
179
|
+
and receiving on `$aws/things/<thing-name>/shadow/*`, which already includes
|
|
180
|
+
the named `dungeon-dice` shadow. No additional certificate policy is needed.
|
|
181
|
+
- The dice recipe grants the component access to those topics through IPC.
|
|
182
|
+
- The Inventory MCP runtime gets `GetThingShadow` and `UpdateThingShadow` on
|
|
183
|
+
only this thing's named `dungeon-dice` shadow.
|
|
184
|
+
|
|
185
|
+
The artifact grant lets the core's token exchange role fetch only
|
|
186
|
+
`com.example.DungeonDice/*`. The deployment depends on component publication.
|
|
187
|
+
|
|
188
|
+
Build, then deploy with all four parameter values:
|
|
189
|
+
|
|
190
|
+
<NxCommands commands={['sync']} />
|
|
191
|
+
<InstallCommand />
|
|
192
|
+
<PackageManagerShortCommand commands={['lint']} />
|
|
193
|
+
<NxCommands commands={['run-many --target build --all']} />
|
|
194
|
+
|
|
195
|
+
<NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @dungeon-adventure/infra:deploy -- "dungeon-adventure-infra-sandbox/**" --parameters dungeon-adventure-infra-sandbox-Application:DiceThingName="$TUTORIAL_THING_NAME" --parameters dungeon-adventure-infra-sandbox-Application:DiceEndpoint="$DICE_IOT_ENDPOINT" --parameters dungeon-adventure-infra-sandbox-Application:TokenExchangeRoleArn="$TUTORIAL_TOKEN_EXCHANGE_ROLE_ARN" --parameters dungeon-adventure-infra-sandbox-Application:ThingGroupArn="$TUTORIAL_THING_GROUP_ARN"']} />
|
|
196
|
+
|
|
197
|
+
Qualify the parameters for the application stack because the WAF stack does not define them.
|
|
198
|
+
|
|
199
|
+
Use `deploy` for this walkthrough. Component/version changes replace
|
|
200
|
+
CloudFormation resources; <Link path="guides/greengrass-component#deployment-revisions">deployment revisions</Link>
|
|
201
|
+
explains the additional rollback flag needed with `deploy-sandbox`.
|
|
202
|
+
|
|
203
|
+
Wait until the component is `RUNNING`:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
|
|
207
|
+
greengrassv2 list-installed-components --core-device-thing-name "$TUTORIAL_THING_NAME" \
|
|
208
|
+
--query "installedComponents[?componentName=='com.example.DungeonDice'].[componentVersion,lifecycleState]" \
|
|
209
|
+
--output table
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 5. Let the agent roll
|
|
213
|
+
|
|
214
|
+
Open the deployed game, start a new conversation or reload the existing one,
|
|
215
|
+
and ask:
|
|
216
|
+
|
|
217
|
+
> "Roll a d20 on the dice device for my attempt to pick this lock."
|
|
218
|
+
|
|
219
|
+
The agent should invoke `roll-dice` and describe the returned value and
|
|
220
|
+
consequence. Read the cloud shadow to compare its `reported.result` with the
|
|
221
|
+
tool result and the agent's reply:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
|
|
225
|
+
iot-data get-thing-shadow --endpoint-url "https://${DICE_IOT_ENDPOINT}" \
|
|
226
|
+
--thing-name "$TUTORIAL_THING_NAME" --shadow-name dungeon-dice \
|
|
227
|
+
/tmp/dungeon-dice-shadow.json
|
|
228
|
+
cat /tmp/dungeon-dice-shadow.json
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
A successful result includes `requestId`, `sides`, `value` and `rolledAt`.
|
|
232
|
+
The device log at `/greengrass/v2/logs/com.example.DungeonDice.log` records the
|
|
233
|
+
same request ID and value. A successful deployment alone does not prove this
|
|
234
|
+
round trip.
|
|
235
|
+
|
|
236
|
+
To exercise the failure path, stop the Greengrass service on this disposable
|
|
237
|
+
core through its Systems Manager terminal, request another roll, and verify
|
|
238
|
+
that the tool reports an error after its bounded wait. The agent should tell
|
|
239
|
+
you the device is unavailable instead of deciding the challenge. Restart the
|
|
240
|
+
service before continuing. An expired pending request must not roll when the
|
|
241
|
+
device reconnects; a new tool call creates a new request.
|
|
242
|
+
|
|
243
|
+
For a version-update exercise, change the component's log message, rebuild and
|
|
244
|
+
run the same deploy command. `NEXT_PATCH` publishes a new version. Confirm the
|
|
245
|
+
new running version, then request another roll.
|
|
246
|
+
|
|
247
|
+
## 6. Keep playing, or remove everything
|
|
248
|
+
|
|
249
|
+
To remove only the extension:
|
|
250
|
+
|
|
251
|
+
1. Record the `DiceArtifactBucket`, `DiceComponentArn` and `DiceDeploymentId`
|
|
252
|
+
outputs from the application stack.
|
|
253
|
+
2. Remove `this.deployment.addComponent(component)` from
|
|
254
|
+
`packages/infra/src/dice-resources.ts`. Redeploy with the same parameters.
|
|
255
|
+
This sends an empty deployment revision; wait until
|
|
256
|
+
`list-installed-components` no longer lists `com.example.DungeonDice`.
|
|
257
|
+
3. Restore the base <Link path="get_started/tutorials/dungeon-game/3">Story Agent prompt</Link>,
|
|
258
|
+
remove the `registerDiceTool` import and call, and restore the
|
|
259
|
+
<Link path="get_started/tutorials/dungeon-game/2#wire-up-the-stack">Module 2 application stack</Link>.
|
|
260
|
+
Rebuild and deploy the dungeon. This removes the MCP permissions and its
|
|
261
|
+
dice configuration.
|
|
262
|
+
4. Delete the retained Greengrass deployment records, component versions and
|
|
263
|
+
artifact bucket using <Link path="get_started/tutorials/greengrass/cleanup#task-3-delete-the-retained-greengrass-resources">the retained-resource cleanup procedure</Link>.
|
|
264
|
+
Substitute `com.example.DungeonDice` for `com.example.Pulse` and use the
|
|
265
|
+
recorded dice outputs. Include every version/revision created by your update
|
|
266
|
+
exercise.
|
|
267
|
+
5. Delete the named shadow, then run the setup script's cleanup and remove the
|
|
268
|
+
owner-managed instance profile and role as described in
|
|
269
|
+
<Link path="get_started/tutorials/greengrass/cleanup">the device cleanup guide</Link>.
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
|
|
273
|
+
iot-data delete-thing-shadow --endpoint-url "https://${DICE_IOT_ENDPOINT}" \
|
|
274
|
+
--thing-name "$TUTORIAL_THING_NAME" --shadow-name dungeon-dice \
|
|
275
|
+
/tmp/dungeon-dice-shadow-deleted.json
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
The dungeon remains deployed after those steps. To remove the whole application,
|
|
279
|
+
continue with <Link path="get_started/tutorials/dungeon-game/wrap-up#destroying-resources">Destroying resources</Link>,
|
|
280
|
+
including its retained user pool, SMS role and conversation-history bucket.
|
|
281
|
+
|
|
282
|
+
## Further experiments
|
|
283
|
+
|
|
284
|
+
- Use a Raspberry Pi with a 64-bit OS and a physical sensor. Keep the request ID
|
|
285
|
+
and timeout contract while replacing `secrets.randbelow`.
|
|
286
|
+
- Use an ESP32 to read the sensor and send its result to the Linux gateway.
|
|
287
|
+
That adds firmware and device authentication; it is not another CPU target
|
|
288
|
+
for this Python component.
|
|
289
|
+
- Split the component into a local dice engine and an MQTT bridge connected
|
|
290
|
+
through Greengrass pub/sub.
|
|
@@ -32,6 +32,12 @@ We recommend you try your hand at extending the codebase with the following capa
|
|
|
32
32
|
|
|
33
33
|
## Destroying resources
|
|
34
34
|
|
|
35
|
+
Want to keep playing and add an edge device first? Continue with
|
|
36
|
+
<Link path="get_started/tutorials/dungeon-game/greengrass-dice">Optional: roll dice with Greengrass</Link>.
|
|
37
|
+
The Story Agent calls a tool that requests a roll from a device and uses the
|
|
38
|
+
returned value in the game. Keep your deployed dungeon for that route; it
|
|
39
|
+
includes instructions to remove just the extension or the whole application.
|
|
40
|
+
|
|
35
41
|
1. To destroy the AWS resources that were created, run the following command:
|
|
36
42
|
|
|
37
43
|
<NxCommands commands={['destroy-sandbox infra']} />
|
|
@@ -40,11 +46,68 @@ We recommend you try your hand at extending the codebase with the following capa
|
|
|
40
46
|
|
|
41
47
|
2. Enter `y` to continue. CloudFormation will destroy your stacks.
|
|
42
48
|
|
|
43
|
-
:::
|
|
44
|
-
|
|
49
|
+
:::note[If AppConfig deletion protection blocks stack deletion]
|
|
50
|
+
Stop using the tutorial app. In the failed stack's **Resources** tab, record
|
|
51
|
+
the exact physical ID of its owned AppConfig application and the IDs of only
|
|
52
|
+
the environment and configuration profiles whose deletion failed.
|
|
53
|
+
|
|
54
|
+
Either wait the account's [deletion protection interval](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_DeletionProtectionSettings.html) after the last configuration
|
|
55
|
+
read and retry destruction, or delete only these discarded tutorial resources:
|
|
56
|
+
use `aws appconfig delete-environment` with `--application-id` and
|
|
57
|
+
`--environment-id`, and `aws appconfig delete-configuration-profile` with
|
|
58
|
+
`--application-id` and `--configuration-profile-id`. Supply the recorded IDs
|
|
59
|
+
and `--deletion-protection-check BYPASS`, with explicit `--profile` and
|
|
60
|
+
`--region`, on each call. Then rerun the destroy command.
|
|
61
|
+
|
|
62
|
+
Use only physical IDs from the failed stack's **Resources** tab. Set the
|
|
63
|
+
profile and Region used to deploy the dungeon, the application ID, and the
|
|
64
|
+
IDs of the specific failed resources:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
export TUTORIAL_AWS_PROFILE=<your-dungeon-profile>
|
|
68
|
+
export TUTORIAL_AWS_REGION=<your-dungeon-region>
|
|
69
|
+
|
|
70
|
+
APP_CONFIG_APPLICATION_ID='application-id-from-failed-stack'
|
|
71
|
+
APP_CONFIG_ENVIRONMENT_ID='environment-id-from-failed-stack'
|
|
72
|
+
APP_CONFIG_CONFIGURATION_PROFILE_ID='configuration-profile-id-from-failed-stack'
|
|
73
|
+
|
|
74
|
+
# Run this only if deletion of that environment failed.
|
|
75
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" appconfig delete-environment \
|
|
76
|
+
--application-id "$APP_CONFIG_APPLICATION_ID" \
|
|
77
|
+
--environment-id "$APP_CONFIG_ENVIRONMENT_ID" \
|
|
78
|
+
--deletion-protection-check BYPASS
|
|
79
|
+
|
|
80
|
+
# Run this only if deletion of that configuration profile failed.
|
|
81
|
+
aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" appconfig delete-configuration-profile \
|
|
82
|
+
--application-id "$APP_CONFIG_APPLICATION_ID" \
|
|
83
|
+
--configuration-profile-id "$APP_CONFIG_CONFIGURATION_PROFILE_ID" \
|
|
84
|
+
--deletion-protection-check BYPASS
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Repeat the configuration profile delete command for each failed profile, setting `APP_CONFIG_CONFIGURATION_PROFILE_ID` to its recorded physical ID.
|
|
88
|
+
:::
|
|
89
|
+
|
|
90
|
+
:::caution[Retained resources]
|
|
91
|
+
Stack deletion leaves these resources for separate cleanup:
|
|
45
92
|
|
|
46
93
|
- The **Cognito user pool**, which `ts#website#auth` creates with deletion protection enabled.
|
|
94
|
+
- The pool's **SMS IAM role**, retained with the pool so it can still be updated and deleted.
|
|
47
95
|
- The **Story Agent's session bucket**, which holds the conversation history and defaults to `RemovalPolicy.RETAIN`.
|
|
96
|
+
- The **Game API access log group**.
|
|
97
|
+
- Four **customer-managed KMS keys** for the user-pool WAF logs, Game API logs, Story Agent sessions and website.
|
|
98
|
+
- The **API Gateway CloudWatch IAM role**, whose regional account setting is shared by REST APIs.
|
|
99
|
+
|
|
100
|
+
Record the SMS role ARN from the user pool's SMS configuration before deleting
|
|
101
|
+
the pool. Turn off the pool's deletion protection, delete the pool, then delete
|
|
102
|
+
its SMS role and any attached policies owned by this application. Empty the
|
|
103
|
+
session bucket, including object versions and delete markers, before deleting it.
|
|
104
|
+
Delete the Game API access log group when you no longer need its logs.
|
|
105
|
+
|
|
106
|
+
Keep any KMS key needed to read data you retain. Schedule deletion of this
|
|
107
|
+
application's unused keys with a waiting period of at least seven days.
|
|
108
|
+
The keys remain in `PendingDeletion` until that period ends.
|
|
48
109
|
|
|
49
|
-
|
|
110
|
+
Preserve the API Gateway role if other REST APIs use it. Check the regional
|
|
111
|
+
account's CloudWatch role setting and dependencies before removing an unused
|
|
112
|
+
tutorial-owned role, and update its account reference before deleting it.
|
|
50
113
|
:::
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Create the component
|
|
3
|
+
description: Create the workspace, a Python project, the Greengrass component and a CDK application, then switch the component from local pub/sub to AWS IoT Core MQTT
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Aside, FileTree } from '@astrojs/starlight/components';
|
|
7
|
+
import CreateNxWorkspaceCommand from '@components/create-nx-workspace-command.astro';
|
|
8
|
+
import E2EDiff from '@components/e2e-diff.astro';
|
|
9
|
+
import Link from '@components/link.astro';
|
|
10
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
11
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
12
|
+
|
|
13
|
+
## Task 1: Create the workspace
|
|
14
|
+
|
|
15
|
+
From the directory that will hold the workspace, run:
|
|
16
|
+
|
|
17
|
+
<CreateNxWorkspaceCommand workspace="greengrass-tutorial" iac="cdk" readonly />
|
|
18
|
+
|
|
19
|
+
Then change into it:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
cd greengrass-tutorial
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The workspace name sets the npm scope `@greengrass-tutorial` and the Python namespace `greengrass_tutorial`. Generated project names carry those prefixes, and `nx run` needs the full name, so the rest of this tutorial uses `greengrass_tutorial.telemetry` and `@greengrass-tutorial/infra`.
|
|
26
|
+
|
|
27
|
+
## Task 2: Generate the projects
|
|
28
|
+
|
|
29
|
+
Create the Python project that hosts the component:
|
|
30
|
+
|
|
31
|
+
<RunGenerator generator="py#project" requiredParameters={{ name: 'telemetry' }} noInteractive readonly />
|
|
32
|
+
|
|
33
|
+
This creates the project `greengrass_tutorial.telemetry` at `packages/telemetry`.
|
|
34
|
+
|
|
35
|
+
Add the Greengrass component to it:
|
|
36
|
+
|
|
37
|
+
<RunGenerator generator="greengrass#component" requiredParameters={{ project: 'telemetry', name: 'pulse', language: 'python', componentName: 'com.example.Pulse', componentVersion: 'NEXT_PATCH', platform: 'linux-amd64', ipc: true, infra: 'component-version', iac: 'cdk' }} noInteractive readonly />
|
|
38
|
+
|
|
39
|
+
Each value matters later in the tutorial:
|
|
40
|
+
|
|
41
|
+
- `platform: linux-amd64` matches the x86_64 instance you provision in module 2. The default is `linux-arm64`, and a recipe built for one architecture does not run on the other.
|
|
42
|
+
- `componentVersion: NEXT_PATCH` allocates the version at deploy time. The first deployment publishes `1.0.0`; module 3 publishes `1.0.1` from a source change without editing the recipe.
|
|
43
|
+
- `ipc: true` is explicit because this tutorial changes the component to publish through Greengrass IPC.
|
|
44
|
+
- `infra: component-version` with `iac: cdk` adds the reusable Greengrass core constructs to `packages/common/constructs` and a `Pulse` app construct that publishes this component's artifact.
|
|
45
|
+
|
|
46
|
+
Create the CDK application that will hold the deployment:
|
|
47
|
+
|
|
48
|
+
<RunGenerator generator="ts#infra" requiredParameters={{ name: 'infra' }} noInteractive readonly />
|
|
49
|
+
|
|
50
|
+
The files this tutorial touches:
|
|
51
|
+
|
|
52
|
+
<FileTree>
|
|
53
|
+
- packages
|
|
54
|
+
- telemetry
|
|
55
|
+
- greengrass
|
|
56
|
+
- pulse
|
|
57
|
+
- main.py the component entrypoint
|
|
58
|
+
- recipe.yaml the component recipe
|
|
59
|
+
- tests
|
|
60
|
+
- greengrass
|
|
61
|
+
- test_pulse.py the component's unit test
|
|
62
|
+
- project.json `pulse-vendor`, `pulse-artifact`, `pulse-deploy-local` and `pulse-logs` targets
|
|
63
|
+
- common
|
|
64
|
+
- constructs
|
|
65
|
+
- src
|
|
66
|
+
- core/greengrass artifact bucket, component version, deployment and version resolver constructs
|
|
67
|
+
- app/greengrass/pulse.ts the `Pulse` construct
|
|
68
|
+
- infra
|
|
69
|
+
- src
|
|
70
|
+
- stacks
|
|
71
|
+
- application-stack.ts where module 3 composes the deployment
|
|
72
|
+
</FileTree>
|
|
73
|
+
|
|
74
|
+
## Task 3: Publish to AWS IoT Core instead of local pub/sub
|
|
75
|
+
|
|
76
|
+
The generated `main.py` publishes a heartbeat with `publish_to_topic`, which reaches other components on the same core device through the local Greengrass pub/sub service. It never leaves the device. To see the heartbeat in AWS IoT Core, the component must use `publish_to_iot_core` from the IPC client, and both the recipe and the device's IoT policy must allow it.
|
|
77
|
+
|
|
78
|
+
Replace the generated `packages/telemetry/greengrass/pulse/main.py`:
|
|
79
|
+
|
|
80
|
+
<E2EDiff before="greengrass-tutorial/main.py.original.template" after="greengrass-tutorial/main.py.template" lang="python" />
|
|
81
|
+
|
|
82
|
+
`publish_to_iot_core` takes the topic name, a QoS of `"1"` (at least once), and a byte payload. The topic `tutorial/greengrass/heartbeat` appears again in the recipe, in the device IoT policy that module 2 creates, and in the MQTT test client subscription in module 3.
|
|
83
|
+
|
|
84
|
+
Replace the access-control block in `packages/telemetry/greengrass/pulse/recipe.yaml`:
|
|
85
|
+
|
|
86
|
+
<E2EDiff before="greengrass-tutorial/recipe.yaml.original.template" after="greengrass-tutorial/recipe.yaml.template" lang="yaml" />
|
|
87
|
+
|
|
88
|
+
The IPC service for AWS IoT Core MQTT is `aws.greengrass.ipc.mqttproxy`, and publishing is the operation `aws.greengrass#PublishToIoTCore`. The resource is the exact topic. This authorization is enforced by the nucleus on the device. The IoT policy attached to the device certificate is enforced by AWS IoT Core, and it needs `iot:Publish` on the same topic. Module 2 creates that policy.
|
|
89
|
+
|
|
90
|
+
Update the generated test, because the host project's `build` runs it and the shared constructs build depends on the host build:
|
|
91
|
+
|
|
92
|
+
<E2EDiff before="greengrass-tutorial/test_pulse.py.original.template" after="greengrass-tutorial/test_pulse.py.template" lang="python" />
|
|
93
|
+
|
|
94
|
+
## Task 4: Build the artifact
|
|
95
|
+
|
|
96
|
+
Run the test and build the component artifact:
|
|
97
|
+
|
|
98
|
+
<NxCommands commands={['run greengrass_tutorial.telemetry:test', 'run greengrass_tutorial.telemetry:pulse-artifact']} />
|
|
99
|
+
|
|
100
|
+
`pulse-artifact` vendors the Python dependencies for `x86_64-manylinux_2_28`, packages `pulse.zip`, and writes the resolved recipe:
|
|
101
|
+
|
|
102
|
+
<FileTree>
|
|
103
|
+
- dist/packages/telemetry/greengrass/pulse/greengrass-build
|
|
104
|
+
- recipes
|
|
105
|
+
- com.example.Pulse-NEXT_PATCH.yaml the recipe with the mqttproxy authorization
|
|
106
|
+
- artifacts
|
|
107
|
+
- com.example.Pulse
|
|
108
|
+
- NEXT_PATCH
|
|
109
|
+
- pulse.zip
|
|
110
|
+
</FileTree>
|
|
111
|
+
|
|
112
|
+
<Aside type="caution" title="Do not run pulse-deploy-local here">
|
|
113
|
+
`pulse-deploy-local` and `pulse-logs` run on a machine that has the Greengrass nucleus and `greengrass-cli` installed. Your workstation is not the core device in this tutorial. Module 2 provisions the device and module 3 deploys to it from the cloud.
|
|
114
|
+
</Aside>
|
|
115
|
+
|
|
116
|
+
Continue with <Link path="get_started/tutorials/greengrass/2">Provision the core device</Link>.
|