@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.
@@ -0,0 +1,198 @@
1
+ ---
2
+ title: Provision the core device
3
+ description: Create an owner-managed instance profile, select the Ubuntu 26.04 x86_64 image, and run the setup script that provisions an EC2 core device with the classic Greengrass nucleus
4
+ ---
5
+
6
+ import { Aside, Code } from '@astrojs/starlight/components';
7
+ import Link from '@components/link.astro';
8
+
9
+ export const setupScriptUrl = `${import.meta.env.SITE}${import.meta.env.BASE_URL.replace(/\/$/, '')}/greengrass/setup-tutorial.sh`;
10
+
11
+ The setup script creates the AWS IoT identity for one core device, launches an Ubuntu 26.04 x86_64 EC2 instance, and installs the classic Greengrass nucleus on it through AWS Systems Manager. It records what it created in `.greengrass-tutorial.env`, bound to your account, Region and prefix, so its `cleanup` operation deletes exactly those resources later.
12
+
13
+ | Resource | Name | Created by |
14
+ | --- | --- | --- |
15
+ | IoT thing group | `<prefix>-group` | Script |
16
+ | IoT thing | `<prefix>-core` | Script |
17
+ | Token exchange role and its access policy | `<prefix>-token-exchange`, `<prefix>-token-exchangeAccess` | Script |
18
+ | IoT role alias | `<prefix>-alias` | Script |
19
+ | Device IoT policy | `<prefix>-device-policy` | Script |
20
+ | EC2 instance | Tagged `Name=<prefix>-core` | Script |
21
+ | Device certificate and private key | Generated on the instance | Nucleus installer |
22
+ | IoT policy for the role alias | `GreengrassTESCertificatePolicy<prefix>-alias` | Nucleus installer |
23
+
24
+ The installer runs on the instance with the instance profile's temporary credentials. The device private key is created on the instance and stays under `/greengrass/v2`. The remote command that the script sends through Systems Manager contains resource names only, so no key or credential enters the Systems Manager command history.
25
+
26
+ ## Task 1: Create the instance profile
27
+
28
+ The script does not create the instance profile. You own it, so you control what the installer is allowed to do. Its role needs `AmazonSSMManagedInstanceCore`, so Systems Manager can run the install command, plus a temporary policy for the installer's `--provision true` path.
29
+
30
+ ```bash
31
+ export TUTORIAL_ACCOUNT_ID=$(aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" \
32
+ sts get-caller-identity --query Account --output text)
33
+
34
+ cat > /tmp/greengrass-tutorial-ec2-trust.json <<'EOF'
35
+ {
36
+ "Version": "2012-10-17",
37
+ "Statement": [
38
+ { "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" }
39
+ ]
40
+ }
41
+ EOF
42
+
43
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam create-role \
44
+ --role-name "${TUTORIAL_PREFIX}-instance" \
45
+ --assume-role-policy-document file:///tmp/greengrass-tutorial-ec2-trust.json
46
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam attach-role-policy \
47
+ --role-name "${TUTORIAL_PREFIX}-instance" \
48
+ --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
49
+ ```
50
+
51
+ The temporary installer policy follows the [minimal IAM policy for the installer](https://docs.aws.amazon.com/greengrass/v2/developerguide/provision-minimal-iam-policy.html). The `CreateIoTResources` statement is the official one. The IAM statement is narrower than the official `CreateTokenExchangeRole` statement: the script creates the token exchange role and its `<role>Access` policy before the installer runs, so the installer only reads them and never needs `iam:CreateRole`, `iam:CreatePolicy` or `iam:AttachRolePolicy`.
52
+
53
+ ```bash
54
+ cat > /tmp/greengrass-tutorial-installer.json <<EOF
55
+ {
56
+ "Version": "2012-10-17",
57
+ "Statement": [
58
+ {
59
+ "Sid": "ReuseTokenExchangeRole",
60
+ "Effect": "Allow",
61
+ "Action": ["iam:GetRole", "iam:PassRole", "iam:GetPolicy"],
62
+ "Resource": [
63
+ "arn:aws:iam::${TUTORIAL_ACCOUNT_ID}:role/${TUTORIAL_PREFIX}-token-exchange",
64
+ "arn:aws:iam::${TUTORIAL_ACCOUNT_ID}:policy/${TUTORIAL_PREFIX}-token-exchangeAccess",
65
+ "arn:aws:iam::aws:policy/${TUTORIAL_PREFIX}-token-exchangeAccess"
66
+ ]
67
+ },
68
+ {
69
+ "Sid": "CreateIoTResources",
70
+ "Effect": "Allow",
71
+ "Action": [
72
+ "iot:AddThingToThingGroup",
73
+ "iot:AttachPolicy",
74
+ "iot:AttachThingPrincipal",
75
+ "iot:CreateKeysAndCertificate",
76
+ "iot:CreatePolicy",
77
+ "iot:CreateRoleAlias",
78
+ "iot:CreateThing",
79
+ "iot:CreateThingGroup",
80
+ "iot:DescribeEndpoint",
81
+ "iot:DescribeRoleAlias",
82
+ "iot:DescribeThingGroup",
83
+ "iot:GetPolicy"
84
+ ],
85
+ "Resource": "*"
86
+ }
87
+ ]
88
+ }
89
+ EOF
90
+
91
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam put-role-policy \
92
+ --role-name "${TUTORIAL_PREFIX}-instance" \
93
+ --policy-name greengrass-installer-bootstrap \
94
+ --policy-document file:///tmp/greengrass-tutorial-installer.json
95
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam create-instance-profile \
96
+ --instance-profile-name "${TUTORIAL_PREFIX}-instance"
97
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam add-role-to-instance-profile \
98
+ --instance-profile-name "${TUTORIAL_PREFIX}-instance" \
99
+ --role-name "${TUTORIAL_PREFIX}-instance"
100
+ ```
101
+
102
+ Task 4 removes `greengrass-installer-bootstrap` again once the device is provisioned.
103
+
104
+ ## Task 2: Select the Ubuntu 26.04 x86_64 image
105
+
106
+ Canonical publishes its current image IDs as public Systems Manager parameters. Read the one for Ubuntu 26.04 on amd64, then confirm the owner, architecture and name before you use it:
107
+
108
+ ```bash
109
+ export TUTORIAL_AMI_ID=$(aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ssm get-parameter \
110
+ --name /aws/service/canonical/ubuntu/server/26.04/stable/current/amd64/hvm/ebs-gp3/ami-id \
111
+ --query Parameter.Value --output text)
112
+
113
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ec2 describe-images \
114
+ --image-ids "$TUTORIAL_AMI_ID" \
115
+ --query 'Images[0].[OwnerId,Architecture,Name]' --output text
116
+ ```
117
+
118
+ The output must show owner `099720109477` (Canonical), architecture `x86_64`, and a name containing `ubuntu-resolute-26.04-amd64-server`. The script checks the same three values and refuses any other image.
119
+
120
+ Ubuntu 26.04 is used for two reasons. It ships `python3.14`, which is the interpreter the generated recipe's `Run` step pins. It also ships `sudo-rs` as the default `sudo`, which can prevent IPC components from starting under Nucleus 2.18.3 because the IPC environment is lost. The script installs `openjdk-21-jre-headless`, `unzip`, `python3.14` and the classic `sudo` package, which provides `/usr/bin/sudo.ws`, then selects `/usr/bin/sudo.ws` as `sudo` and verifies the selection before it installs the nucleus. On the Canonical image both `sudo` and `sudo-rs` are preinstalled, so the alternatives switch is the effective step. See the <Link path="guides/greengrass-component#troubleshooting-and-service-limits">component troubleshooting notes</Link>.
121
+
122
+ ## Task 3: Download and run the setup script
123
+
124
+ Download the script from this documentation site, read it, then run it from the workspace root:
125
+
126
+ <Code lang="bash" code={`curl -fsSLo setup-greengrass-tutorial.sh ${setupScriptUrl}\nchmod +x setup-greengrass-tutorial.sh\nless setup-greengrass-tutorial.sh`} />
127
+
128
+ The same file is checked into the repository at `docs/public/greengrass/setup-tutorial.sh`.
129
+
130
+ ```bash
131
+ ./setup-greengrass-tutorial.sh setup \
132
+ --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" --prefix "$TUTORIAL_PREFIX" \
133
+ --ami-id "$TUTORIAL_AMI_ID" --instance-profile "${TUTORIAL_PREFIX}-instance"
134
+ ```
135
+
136
+ Pass `--subnet-id <subnet-id>` when the Region has no default VPC. Pass `--instance-type` to change the default `t3.small`.
137
+
138
+ The script performs these steps in order, and writes the state file after each created resource:
139
+
140
+ 1. Resolves the caller identity, validates the image, and checks that the instance profile exists.
141
+ 2. Checks that none of the resources in the table above exist yet. An existing thing group, thing, role, policy or role alias under the prefix stops the script before it creates anything.
142
+ 3. Creates the thing group and thing, the token exchange role with its access policy, the role alias, and the device IoT policy. The IoT policy is the [minimal core device policy](https://docs.aws.amazon.com/greengrass/v2/developerguide/device-auth.html#greengrass-core-minimal-iot-policy) from the developer guide, plus `iot:Publish` on `arn:aws:iot:<region>:<account-id>:topic/tutorial/greengrass/heartbeat`.
143
+ 4. Launches the instance with the instance profile and IMDSv2 required, waits for it to register with Systems Manager, and sends one `AWS-RunShellScript` command that installs the prerequisites, switches `sudo`, downloads Greengrass nucleus 2.18.3, and runs the installer with `--provision true --setup-system-service true`, the thing, group, policy, role and alias names above, and `--component-default-user ggc_user:ggc_group`.
144
+ 5. Polls the command until it finishes, then records the certificate the installer attached to the thing and waits for the core device to appear in Greengrass.
145
+
146
+ Setup takes about ten minutes. When it finishes, load the recorded values into your shell and keep the state file out of Git:
147
+
148
+ ```bash
149
+ source .greengrass-tutorial.env
150
+ echo .greengrass-tutorial.env >> .gitignore
151
+ ```
152
+
153
+ The state file exports `TUTORIAL_THING_NAME`, `TUTORIAL_THING_GROUP_ARN`, `TUTORIAL_TOKEN_EXCHANGE_ROLE_ARN`, `TUTORIAL_INSTANCE_ID`, `TUTORIAL_CERTIFICATE_ARN` and the identity it is bound to. Module 3 passes two of them to the CDK stack.
154
+
155
+ <Aside type="note" title="Reruns and failures">
156
+ Running `setup` again after a successful run reports the existing instance and changes nothing. If a run stops part way, for example because the install command fails, the state file records how far it got and a rerun refuses to continue. Run `cleanup` with the same profile, Region and prefix, fix the cause, then run `setup` again. Cleanup only touches the resources the state file records, tolerates objects that are already gone, and stops on any other error.
157
+ </Aside>
158
+
159
+ ## Task 4: Remove the temporary installer permissions
160
+
161
+ The installer has finished. Remove the bootstrap policy so the instance keeps Systems Manager access only:
162
+
163
+ ```bash
164
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam delete-role-policy \
165
+ --role-name "${TUTORIAL_PREFIX}-instance" \
166
+ --policy-name greengrass-installer-bootstrap
167
+ ```
168
+
169
+ ## Task 5: Check the device
170
+
171
+ The nucleus registers the core device on its first start. Confirm it from the cloud:
172
+
173
+ ```bash
174
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 get-core-device \
175
+ --core-device-thing-name "$TUTORIAL_THING_NAME" \
176
+ --query '{status: status, coreVersion: coreVersion, platform: platform, architecture: architecture}'
177
+ ```
178
+
179
+ Expect `HEALTHY`, `linux`, and `amd64`. To read a log on the instance, send a Systems Manager command with a parameters file. The first line is a shebang, which `AWS-RunShellScript` honours:
180
+
181
+ ```bash
182
+ cat > /tmp/greengrass-tutorial-command.json <<'EOF'
183
+ { "commands": ["#!/bin/bash", "tail -n 20 /greengrass/v2/logs/greengrass.log"] }
184
+ EOF
185
+
186
+ TUTORIAL_COMMAND_ID=$(aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ssm send-command \
187
+ --instance-ids "$TUTORIAL_INSTANCE_ID" --document-name AWS-RunShellScript \
188
+ --parameters file:///tmp/greengrass-tutorial-command.json \
189
+ --query Command.CommandId --output text)
190
+ sleep 5
191
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ssm get-command-invocation \
192
+ --command-id "$TUTORIAL_COMMAND_ID" --instance-id "$TUTORIAL_INSTANCE_ID" \
193
+ --query StandardOutputContent --output text
194
+ ```
195
+
196
+ Module 3 uses the same pattern to read the component's own log.
197
+
198
+ Continue with <Link path="get_started/tutorials/greengrass/3">Deploy, observe and update</Link>.
@@ -0,0 +1,131 @@
1
+ ---
2
+ title: Deploy, observe and update
3
+ description: Compose the artifact repository, read grant, component version and deployment in CDK, watch the heartbeat arrive in AWS IoT Core, then publish a NEXT_PATCH update
4
+ ---
5
+
6
+ import { Aside } from '@astrojs/starlight/components';
7
+ import E2EDiff from '@components/e2e-diff.astro';
8
+ import InstallCommand from '@components/install-command.astro';
9
+ import Link from '@components/link.astro';
10
+ import NxCommands from '@components/nx-commands.astro';
11
+
12
+ ## Task 1: Compose the stack
13
+
14
+ The generator vended building blocks, not a deployment. Your stack decides where artifacts live, which role may read them, and which fleet receives the component. Replace `packages/infra/src/stacks/application-stack.ts`:
15
+
16
+ <E2EDiff before="greengrass-tutorial/application-stack.ts.original.template" after="greengrass-tutorial/application-stack.ts.template" lang="typescript" />
17
+
18
+ What each part does:
19
+
20
+ - `GreengrassArtifactBucket` creates the retained, versioned, TLS-only artifact repository. `grantReadTo` gives the token exchange role `s3:GetObject` on `com.example.Pulse/*`, which covers every artifact key the resolver writes for this component.
21
+ - `Pulse` extends `GreengrassComponentVersion`. It reads the recipe and `pulse.zip` that `pulse-artifact` built, uploads the archive under a content-hashed key, and publishes the component version. Its `bucket` property takes the `GreengrassArtifactBucket` construct itself.
22
+ - `GreengrassDeployment` with `targetArn` deploys to the thing group the setup script created. `addComponent(pulse)` puts the resolved version into the deployment's component map and adds a CloudFormation dependency on the component version resource, so the IoT job cannot reach the device before the version exists.
23
+ - The two `CfnParameter` values come from `.greengrass-tutorial.env`. Passing them as parameters keeps the stack free of account-specific literals and lets the e2e suite synthesize the same file.
24
+
25
+ ## Task 2: Bootstrap and deploy
26
+
27
+ Load the recorded values, synchronize project references and dependency manifests, install the updated workspace dependencies, and bootstrap CDK in the account and Region if you have not done so before:
28
+
29
+ ```bash
30
+ source .greengrass-tutorial.env
31
+ ```
32
+
33
+ <NxCommands commands={['sync']} />
34
+ <InstallCommand />
35
+ <NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @greengrass-tutorial/infra:bootstrap']} />
36
+
37
+ Deploy the stack. `packages/infra/src/main.ts` places the stack in the stage `greengrass-tutorial-infra-sandbox`, and the `deploy` target runs `cdk deploy` without a stage of its own, so the command names that stage and passes the role and thing group ARNs as CloudFormation parameters:
38
+
39
+ <NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @greengrass-tutorial/infra:deploy -- "greengrass-tutorial-infra-sandbox/**" --parameters TokenExchangeRoleArn="$TUTORIAL_TOKEN_EXCHANGE_ROLE_ARN" --parameters ThingGroupArn="$TUTORIAL_THING_GROUP_ARN"']} />
40
+
41
+ `deploy` depends on `^assemble`, and the shared constructs project depends on the telemetry project's `assemble`, which runs `pulse-artifact`. Every deploy therefore publishes the artifact that matches your current source. The target runs `cdk deploy` without express mode, so it accepts a later deployment revision that replaces the deployment resource. Read <Link path="guides/greengrass-component#deployment-revisions">deployment revisions</Link> before using `deploy-sandbox` for Greengrass.
42
+
43
+ On the first deploy the version resolver finds no published version of `com.example.Pulse` and publishes `1.0.0`. The deployment then reaches the thing group, and the core device downloads the artifact with the token exchange role and starts the component. Allow one to two minutes after the stack completes.
44
+
45
+ ## Task 3: Watch the heartbeat
46
+
47
+ Open the AWS IoT console in `$TUTORIAL_AWS_REGION`, choose **MQTT test client**, and subscribe to the topic:
48
+
49
+ ```text
50
+ tutorial/greengrass/heartbeat
51
+ ```
52
+
53
+ Every 30 seconds a message arrives:
54
+
55
+ ```json
56
+ {"sequence": 3, "greeting": "hello from pulse"}
57
+ ```
58
+
59
+ The AWS CLI cannot subscribe to MQTT topics. If you prefer your own MQTT client, connect it to the account's data endpoint with its own certificate and policy, which this tutorial does not create:
60
+
61
+ ```bash
62
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iot describe-endpoint \
63
+ --endpoint-type iot:Data-ATS --query endpointAddress --output text
64
+ ```
65
+
66
+ ## Task 4: Check the device
67
+
68
+ A successful deployment proves the device applied the deployment document. It does not prove the component runs. Check the installed component's lifecycle state:
69
+
70
+ ```bash
71
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 list-installed-components \
72
+ --core-device-thing-name "$TUTORIAL_THING_NAME" \
73
+ --query 'installedComponents[?componentName==`com.example.Pulse`].[componentVersion,lifecycleState]' \
74
+ --output text
75
+ ```
76
+
77
+ Expect `1.0.0` and `RUNNING`. Then read the component's own log on the instance with the Systems Manager pattern from module 2:
78
+
79
+ ```bash
80
+ cat > /tmp/greengrass-tutorial-command.json <<'EOF'
81
+ { "commands": ["#!/bin/bash", "tail -n 20 /greengrass/v2/logs/com.example.Pulse.log"] }
82
+ EOF
83
+
84
+ TUTORIAL_COMMAND_ID=$(aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ssm send-command \
85
+ --instance-ids "$TUTORIAL_INSTANCE_ID" --document-name AWS-RunShellScript \
86
+ --parameters file:///tmp/greengrass-tutorial-command.json \
87
+ --query Command.CommandId --output text)
88
+ sleep 5
89
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" ssm get-command-invocation \
90
+ --command-id "$TUTORIAL_COMMAND_ID" --instance-id "$TUTORIAL_INSTANCE_ID" \
91
+ --query StandardOutputContent --output text
92
+ ```
93
+
94
+ The log shows the IPC connection and one line per heartbeat:
95
+
96
+ ```text
97
+ INFO:awsiot.eventstreamrpc:<Connection ...> /greengrass/v2/ipc.socket:0> connected
98
+ INFO:com.example.Pulse:Published heartbeat 0 to tutorial/greengrass/heartbeat
99
+ INFO:com.example.Pulse:Published heartbeat 1 to tutorial/greengrass/heartbeat
100
+ ```
101
+
102
+ If the deployment reports `SUCCEEDED` but the component is `BROKEN`, or `get-core-device` reports `UNHEALTHY`, follow the <Link path="guides/greengrass-component#troubleshooting-and-service-limits">component troubleshooting steps</Link>.
103
+
104
+ ## Task 5: Update the component
105
+
106
+ Change the greeting in `packages/telemetry/greengrass/pulse/main.py`:
107
+
108
+ <E2EDiff before="greengrass-tutorial/main.py.template" after="greengrass-tutorial/main.py.updated.template" lang="python" />
109
+
110
+ Deploy again with the same command:
111
+
112
+ <NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @greengrass-tutorial/infra:deploy -- "greengrass-tutorial-infra-sandbox/**" --parameters TokenExchangeRoleArn="$TUTORIAL_TOKEN_EXCHANGE_ROLE_ARN" --parameters ThingGroupArn="$TUTORIAL_THING_GROUP_ARN"']} />
113
+
114
+ Nx sees the changed source and rebuilds `pulse-artifact`. The archive's content hash changes, so the resolver allocates `1.0.1`, the artifact is uploaded under a new key, a new component version is published, and a new deployment revision points the thing group at it. The recipe still says `NEXT_PATCH`; nothing in the workspace records the number.
115
+
116
+ Verify both the installed version and the payload:
117
+
118
+ ```bash
119
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 list-installed-components \
120
+ --core-device-thing-name "$TUTORIAL_THING_NAME" \
121
+ --query 'installedComponents[?componentName==`com.example.Pulse`].[componentVersion,lifecycleState]' \
122
+ --output text
123
+ ```
124
+
125
+ Expect `1.0.1` and `RUNNING`. In the MQTT test client the greeting changes to `hello from the updated pulse`, and the sequence restarts from `0` because the component process was restarted.
126
+
127
+ <Aside type="tip" title="Unchanged redeploys">
128
+ Deploying again without a source or recipe change reuses `1.0.1`. The resolver compares the content hash with the tag on the highest published version and returns that version instead of allocating a new one. Read <Link path="guides/greengrass-component#automatic-versioning">automatic versioning</Link> for the rules and their limits.
129
+ </Aside>
130
+
131
+ Continue with <Link path="get_started/tutorials/greengrass/cleanup">Remove and clean up</Link>.
@@ -0,0 +1,137 @@
1
+ ---
2
+ title: Remove and clean up
3
+ description: Remove the component from the device with an empty deployment revision, destroy the stack, then delete the retained Greengrass resources and everything the setup script created
4
+ ---
5
+
6
+ import { Aside } from '@astrojs/starlight/components';
7
+ import E2EDiff from '@components/e2e-diff.astro';
8
+ import Link from '@components/link.astro';
9
+ import NxCommands from '@components/nx-commands.astro';
10
+
11
+ Cleanup runs in the reverse order of creation: first the device stops running the component, then the stack goes, then the resources the stack retained, then the device and its identity, and finally the instance profile.
12
+
13
+ ## Task 1: Remove the component from the device
14
+
15
+ Deleting a deployment resource removes deployment management state. It does not uninstall anything from a device. The device only removes a component when it receives a deployment revision that no longer lists it. Change the stack so the deployment lists no components while the published version stays managed:
16
+
17
+ <E2EDiff before="greengrass-tutorial/application-stack.ts.template" after="greengrass-tutorial/application-stack.ts.removed.template" lang="typescript" />
18
+
19
+ Deploy the revision:
20
+
21
+ <NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @greengrass-tutorial/infra:deploy -- "greengrass-tutorial-infra-sandbox/**" --parameters TokenExchangeRoleArn="$TUTORIAL_TOKEN_EXCHANGE_ROLE_ARN" --parameters ThingGroupArn="$TUTORIAL_THING_GROUP_ARN"']} />
22
+
23
+ Wait until the component disappears from the device and the device stays healthy:
24
+
25
+ ```bash
26
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 list-installed-components \
27
+ --core-device-thing-name "$TUTORIAL_THING_NAME" \
28
+ --query 'installedComponents[].componentName' --output text
29
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 get-core-device \
30
+ --core-device-thing-name "$TUTORIAL_THING_NAME" --query status --output text
31
+ ```
32
+
33
+ The first command must not list `com.example.Pulse` any more. The second must print `HEALTHY`. The MQTT test client stops receiving heartbeats.
34
+
35
+ ## Task 2: Destroy the stack
36
+
37
+ <NxCommands env={{ AWS_PROFILE: '"$TUTORIAL_AWS_PROFILE"', AWS_REGION: '"$TUTORIAL_AWS_REGION"' }} commands={['run @greengrass-tutorial/infra:destroy -- "greengrass-tutorial-infra-sandbox/**" --force']} />
38
+
39
+ The stack is gone, but three kinds of resources are retained on purpose, because component versions are immutable and outlive any single deployment:
40
+
41
+ - Both component versions of `com.example.Pulse`, `1.0.0` and `1.0.1`.
42
+ - The three deployment revisions to the thing group.
43
+ - The artifact bucket, with one archive per published version.
44
+
45
+ The CDK bootstrap stack `CDKToolkit` also remains. It is shared by every CDK application in the account and Region, so leave it unless you created it for this tutorial.
46
+
47
+ CDK leaves the Lambda log groups for component version resolution, the
48
+ custom-resource framework, and `BucketDeployment` after stack deletion; delete
49
+ them separately if you no longer need their logs.
50
+
51
+ ## Task 3: Delete the retained Greengrass resources
52
+
53
+ List the deployments to the thing group. Cancel the one still `ACTIVE`, then delete each of them:
54
+
55
+ ```bash
56
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 list-deployments \
57
+ --target-arn "$TUTORIAL_THING_GROUP_ARN" --history-filter ALL \
58
+ --query 'deployments[].[deploymentId,deploymentStatus]' --output text
59
+
60
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 cancel-deployment \
61
+ --deployment-id <active-deployment-id>
62
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 delete-deployment \
63
+ --deployment-id <deployment-id>
64
+ ```
65
+
66
+ Delete every published version of the component:
67
+
68
+ ```bash
69
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 list-component-versions \
70
+ --arn "arn:aws:greengrass:${TUTORIAL_AWS_REGION}:${TUTORIAL_ACCOUNT_ID}:components:com.example.Pulse" \
71
+ --query 'componentVersions[].arn' --output text
72
+
73
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" greengrassv2 delete-component \
74
+ --arn <component-version-arn>
75
+ ```
76
+
77
+ Find the artifact bucket through the ownership tag the construct applies, confirm that the list holds only this tutorial's bucket, then delete its object versions and the bucket:
78
+
79
+ ```bash
80
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" resourcegroupstaggingapi get-resources \
81
+ --tag-filters Key=greengrass-artifact-repository,Values=true \
82
+ --resource-type-filters s3:bucket \
83
+ --query 'ResourceTagMappingList[].ResourceARN' --output text
84
+
85
+ export TUTORIAL_BUCKET=<bucket-name>
86
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" s3api list-object-versions \
87
+ --bucket "$TUTORIAL_BUCKET" \
88
+ --query '{Objects: Versions[].{Key: Key, VersionId: VersionId}}' --output json \
89
+ > /tmp/greengrass-tutorial-versions.json
90
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" s3api delete-objects \
91
+ --bucket "$TUTORIAL_BUCKET" --delete file:///tmp/greengrass-tutorial-versions.json
92
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" s3api delete-bucket \
93
+ --bucket "$TUTORIAL_BUCKET"
94
+ ```
95
+
96
+ The bucket is versioned, so `delete-objects` must name each version. If `list-object-versions` also reports `DeleteMarkers`, repeat the delete with those entries before deleting the bucket.
97
+
98
+ ## Task 4: Remove the core device and its identity
99
+
100
+ The script's `cleanup` operation reads `.greengrass-tutorial.env`, checks that it belongs to the same account, Region and prefix, and then terminates the instance, detaches and deletes the certificate with every policy attached to it, deletes the core device record, the thing and the thing group, both IoT policies, the role alias, the token exchange role with its attachments, and the access policy.
101
+
102
+ ```bash
103
+ ./setup-greengrass-tutorial.sh cleanup \
104
+ --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" --prefix "$TUTORIAL_PREFIX"
105
+ ```
106
+
107
+ Each step prints `deleted` or `absent`. An object that is already gone is skipped. Any other error stops the run and keeps the state file, so you can fix the cause and rerun the same command.
108
+
109
+ <Aside type="note" title="Order matters for the role">
110
+ Destroy the stack before running cleanup. The stack's read grant is an inline policy on the token exchange role. Cleanup deletes inline policies it finds so the role can be removed, but a stack that still references the role would then fail its next update.
111
+ </Aside>
112
+
113
+ ## Task 5: Remove the instance profile
114
+
115
+ The instance profile was yours, so the script leaves it alone:
116
+
117
+ ```bash
118
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam remove-role-from-instance-profile \
119
+ --instance-profile-name "${TUTORIAL_PREFIX}-instance" --role-name "${TUTORIAL_PREFIX}-instance"
120
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam delete-instance-profile \
121
+ --instance-profile-name "${TUTORIAL_PREFIX}-instance"
122
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam detach-role-policy \
123
+ --role-name "${TUTORIAL_PREFIX}-instance" \
124
+ --policy-arn arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
125
+ aws --profile "$TUTORIAL_AWS_PROFILE" --region "$TUTORIAL_AWS_REGION" iam delete-role \
126
+ --role-name "${TUTORIAL_PREFIX}-instance"
127
+ rm -f .greengrass-tutorial.env
128
+ ```
129
+
130
+ ## What you learned
131
+
132
+ - A generated component publishes over local IPC by default. Cloud MQTT needs `publish_to_iot_core`, a `aws.greengrass.ipc.mqttproxy` authorization in the recipe, and `iot:Publish` in the device's IoT policy.
133
+ - The generator vends building blocks. Your CDK stack owns the artifact repository, the read grant, and the deployment, and `addComponent` carries the resolved version and the ordering edge.
134
+ - `NEXT_PATCH` allocates a version from content. A source change publishes the next patch version through the normal `deploy`.
135
+ - Removing a component is a deployment revision. Deleting infrastructure is a separate, later step that leaves retained versions, deployments and the bucket for you to delete.
136
+
137
+ For versioning and artifact retention, read the <Link path="guides/greengrass-component#automatic-versioning">versioning</Link> and <Link path="guides/greengrass-component#artifact-storage-and-retention">artifact storage</Link> sections of the component guide. The same guide lists the service limits to consider for larger deployments.
@@ -0,0 +1,65 @@
1
+ ---
2
+ title: Greengrass MQTT tutorial
3
+ description: Build a Python Greengrass component, run it on an EC2 core device, watch its heartbeat arrive in AWS IoT Core over MQTT, publish a NEXT_PATCH update, then remove everything
4
+ ---
5
+
6
+ import Link from '@components/link.astro';
7
+ import Snippet from '@components/snippet.astro';
8
+
9
+ In this tutorial you build a Python [AWS IoT Greengrass v2](https://docs.aws.amazon.com/greengrass/v2/developerguide/what-is-iot-greengrass.html) component with `@aws/nx-plugin`, run it on an Ubuntu 26.04 x86_64 EC2 instance that acts as the core device, and watch its heartbeat arrive in AWS IoT Core over MQTT. You then change the source, publish the next version with `NEXT_PATCH`, remove the component from the device, and delete every resource you created.
10
+
11
+ The tutorial uses CDK and the classic Greengrass nucleus. For TypeScript components, Terraform, or an existing fleet, read the <Link path="guides/greengrass-component">Greengrass component guide</Link>.
12
+
13
+ ## What you build
14
+
15
+ | Piece | Where | Created by |
16
+ | --- | --- | --- |
17
+ | Python project `greengrass_tutorial.telemetry` | `packages/telemetry` | `py#project` |
18
+ | Component `com.example.Pulse` | `packages/telemetry/greengrass/pulse` | `greengrass#component` |
19
+ | Greengrass core constructs and the `Pulse` app construct | `packages/common/constructs/src/core/greengrass`, `packages/common/constructs/src/app/greengrass` | `greengrass#component` |
20
+ | CDK application `@greengrass-tutorial/infra` | `packages/infra` | `ts#infra` |
21
+
22
+ The generated component publishes over local Greengrass IPC. Module 1 changes it to publish to AWS IoT Core, which needs a different IPC operation, a different recipe authorization, and an IoT policy statement on the device. The API and access-control names come from the [AWS IoT Core MQTT IPC documentation](https://docs.aws.amazon.com/greengrass/v2/developerguide/ipc-iot-core-mqtt.html).
23
+
24
+ ## What it creates in AWS
25
+
26
+ | Resource | Created by | Deleted by |
27
+ | --- | --- | --- |
28
+ | IoT thing group, thing, certificate, IoT policy, token exchange role, role alias, IAM access policy | The setup script and the nucleus installer | The script's `cleanup` operation |
29
+ | EC2 `t3.small` instance with an SSM instance profile | The setup script (instance) and you (instance profile) | The script's `cleanup` operation and you |
30
+ | Artifact bucket, component versions, deployment, artifact read grant | Your CDK stack | `destroy`, then manual deletion of the retained bucket, versions and deployments |
31
+
32
+ The instance runs until you clean up. Use an AWS account and Region you can clean up completely.
33
+
34
+ ## Before you start
35
+
36
+ <Snippet name="required-prerequisites" />
37
+
38
+ You also need:
39
+
40
+ - [AWS CLI v2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) with a named profile for the target account.
41
+ - Permissions in that account to create IAM roles and policies, IoT things and policies, EC2 instances, Systems Manager commands, S3 buckets, CloudFormation stacks and Greengrass resources.
42
+ - A default VPC in the Region, or a subnet with outbound internet access that you pass to the setup script.
43
+
44
+ Every AWS CLI command in this tutorial passes `--profile` and `--region` explicitly, and every CDK command receives `AWS_PROFILE` and `AWS_REGION`. Set the values once in your shell:
45
+
46
+ ```bash
47
+ export TUTORIAL_AWS_PROFILE=<your-profile>
48
+ export TUTORIAL_AWS_REGION=us-east-1
49
+ export TUTORIAL_PREFIX=gg-tutorial
50
+ ```
51
+
52
+ `TUTORIAL_PREFIX` names every resource the setup script creates. Pick a value that nothing else in the account uses.
53
+
54
+ ## What is verified automatically
55
+
56
+ The commands, source edits, build and CDK synthesis of this tutorial are covered by the `greengrass-tutorial` smoke test in CI. The setup script's identity, refusal and cleanup behaviour runs against a recorded AWS CLI in the docs test suite.
57
+
58
+ Provisioning, MQTT delivery, device updates and cleanup require an AWS account and remain outside the automated lane. Follow the device checks in each module to verify the deployment. The <Link path="guides/greengrass-component#hardware-and-operating-systems">hardware support table</Link> records the supported device platforms.
59
+
60
+ ## Modules
61
+
62
+ 1. <Link path="get_started/tutorials/greengrass/1">Create the component</Link>: workspace, Python project, component, CDK application, and the switch to AWS IoT Core MQTT.
63
+ 2. <Link path="get_started/tutorials/greengrass/2">Provision the core device</Link>: instance profile, image selection, the setup script, and what it creates.
64
+ 3. <Link path="get_started/tutorials/greengrass/3">Deploy, observe and update</Link>: the CDK stack, the first deployment, the MQTT heartbeat, and a `NEXT_PATCH` update.
65
+ 4. <Link path="get_started/tutorials/greengrass/cleanup">Remove and clean up</Link>: an empty deployment revision, stack destruction, and deletion of the retained and script-created resources.
@@ -42,7 +42,7 @@ The generator modifies the following files in your agent's source directory:
42
42
 
43
43
  - packages/my-service/src/my-agent
44
44
  - agent.ts Prisma client fetched inside `getAgent` and available to tools
45
- - Dockerfile RDS CA bundle installed for SSL connections to Aurora (only when the agent's `infra` is `agentcore-ecr`)
45
+ - Dockerfile RDS CA bundle installed and `NODE_EXTRA_CA_CERTS` set for SSL connections to Aurora (only when the agent's `infra` is `agentcore-ecr`)
46
46
 
47
47
  </FileTree>
48
48
 
@@ -42,7 +42,7 @@ The generator modifies the following files in your MCP server's source directory
42
42
 
43
43
  - packages/my-service/src/my-mcp
44
44
  - server.ts Prisma client fetched and available to all tools registered inside `createServer`
45
- - Dockerfile RDS CA bundle installed for SSL connections to Aurora (only when the MCP server's `infra` is `agentcore-ecr`)
45
+ - Dockerfile RDS CA bundle installed and `NODE_EXTRA_CA_CERTS` set for SSL connections to Aurora (only when the MCP server's `infra` is `agentcore-ecr`)
46
46
 
47
47
  </FileTree>
48
48
 
@@ -632,7 +632,9 @@ The recipe grants `aws.greengrass#PublishToTopic` on
632
632
  reaches other components on the same core device, not AWS IoT Core. To publish
633
633
  to AWS IoT Core, call `publish_to_iot_core`, grant
634
634
  `aws.greengrass#PublishToIoTCore` under `aws.greengrass.ipc.mqttproxy` in the
635
- recipe, and give the device's IoT policy `iot:Publish` on the exact topic.
635
+ recipe, and give the device's IoT policy `iot:Publish` on the exact topic. The
636
+ <Link path="get_started/tutorials/greengrass/overview">tutorial</Link> shows
637
+ that flow end to end.
636
638
  </TabItem>
637
639
  <TabItem label="TypeScript" _filter={{ language: 'typescript' }}>
638
640
  With the default `ipc: false`, `main.ts` logs a line every 30 seconds and the
@@ -767,3 +769,7 @@ Greengrass limits one component to 5,000 versions per Region and
767
769
  limited to 16 KB, and a deployment document to 31 KB for a thing group or 7 KB
768
770
  for a single thing. Avoid using new versions as heartbeats and split large
769
771
  deployments into smaller batches.
772
+
773
+ ## Next steps
774
+
775
+ - <Link path="get_started/tutorials/greengrass/overview">Greengrass MQTT tutorial</Link>: Python, CDK, an EC2 core device, a cloud MQTT heartbeat, and a `NEXT_PATCH` update.