Skip to content

Commit b232aa3

Browse files
authored
Greengrass IPC post-release followup (#367)
* Shuffle greengrass IPC user guide location, update echo client and service model, add greengrass ipc component sample
1 parent f4ca5e3 commit b232aa3

File tree

13 files changed

+227
-4
lines changed

13 files changed

+227
-4
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,4 @@ config.ts
206206
docs/
207207

208208
# don't track sample package locks
209-
samples/node/*/package-lock.json
210-
samples/browser/*/package-lock.json
209+
samples/**/package-lock.json

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ to JS by the [awscrt](https://github.com/awslabs/aws-crt-nodejs) package.
2222

2323
## What's New
2424

25+
The SDK now supports Greengrass IPC. See the [Greengrass IPC User Guide](https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/documents/GreengrassIPC.md)
26+
or the [API Documentation](https://aws.github.io/aws-iot-device-sdk-js-v2/node/modules/greengrasscoreipc.html) for more information.
27+
2528
The SDK now supports MQTT5. See the [MQTT5 User Guide](https://github.com/awslabs/aws-crt-nodejs/blob/main/MQTT5-UserGuide.md)
2629
or the API Documentation for [NodeJS](https://awslabs.github.io/aws-crt-nodejs/node/modules/mqtt5.html) or
2730
the [browser](https://awslabs.github.io/aws-crt-nodejs/browser/modules/mqtt5.html) for more information. There is also a [MQTT5 sample for NodeJS](https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/node/pub_sub_mqtt5) and a [MQTT5 sample for the browser](https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/browser/pub_sub_mqtt5).

docsrc/typedoc-node.json

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"entryPoints": [
3+
"../lib/eventstream_rpc.ts",
34
"../lib/greengrass/discoveryclient.ts",
5+
"../lib/greengrasscoreipc.ts",
6+
"../lib/greengrasscoreipc/client.ts",
47
"../lib/iotidentity/iotidentityclient.ts",
58
"../lib/iotjobs/iotjobsclient.ts",
69
"../lib/iotshadow/iotshadowclient.ts",

GreengrassIPC.md renamed to documents/GreengrassIPC.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ The Javascript Greengrass IPC implementation has several differences relative to
3636
* Single client - Other v2 IoT SDKs have both a v1 and v2 client, where the v1 client is low-level and more verbose (and complex) in usage, while the v2 client is streamlined and less prone to accidental misuse. Javascript Greengrass IPC skips the v1 client and starts directly with the v2 client approach.
3737

3838
## Greengrass IPC Example
39-
For those who prefer to dive right in, you can start with our [Greengrass IPC example](./samples/node/gg_pic/index.ts).
40-
The associated [README](./samples/node/gg_ipc/README.md) contains instructions for how to perform a local greengrass deployment of the sample
39+
For those who prefer to dive right in, you can start with our [Greengrass IPC example](https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/node/gg_ipc).
40+
The associated [README](https://github.com/aws/aws-iot-device-sdk-js-v2/blob/main/samples/node/gg_ipc/README.md) contains instructions for how to perform a local greengrass deployment of the sample
4141
as a component.
4242

4343
## Greengrass IPC Client

lib/echotestrpc/client.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
/* This file is generated */
7+
68

79
/**
810
* @packageDocumentation

lib/echotestrpc/model.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
/* This file is generated */
7+
68

79
/**
810
* @packageDocumentation

lib/echotestrpc/model_utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
/* This file is generated */
7+
68
import * as eventstream_rpc_utils from "../eventstream_rpc_utils";
79
import * as model from "./model";
810
import {eventstream} from "aws-crt";

lib/eventstream_rpc.ts

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ export class RpcError extends Error {
168168
/** Optional service-specific modelled error data */
169169
readonly serviceError?: any;
170170

171+
/** @internal */
171172
constructor(model: RpcErrorModel) {
172173
super(model.description);
173174

samples/node/gg_ipc/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Node: Greengrass IPC
2+
3+
[**Return to main sample list**](../../README.md)
4+
5+
This sample uses the AWS IoT [Greengrass IPC Client](https://aws.github.io/aws-iot-device-sdk-js-v2/node/modules/greengrasscoreipc) to defined a Greengrass component that subscribes to MQTT messages
6+
on a topic in AWS IoT Core and periodically publishes messages to that topic.
7+
8+
Note: For this sample to work, you must have configured and installed the AWS Greengrass software on the local host. The IAM role
9+
assumed by the Greengrass Nucleus must also include permissions to connect, subscribe, and publish to AWS IoT Core.
10+
11+
## Deploying the Component
12+
13+
First, go to the `./artifacts/com.amazon.RpcTest/1.0.0` folder and run the following command:
14+
15+
``` sh
16+
npm install
17+
```
18+
19+
Then, from this folder, run the following Greengrass CLI command:
20+
21+
Linux:
22+
``` sh
23+
sudo <path-to-greengrass-cli-executable> deployment create --recipeDir ./recipes --artifactDir ./artifacts --merge "com.amazon.RpcTest=1.0.0"
24+
```
25+
26+
Windows:
27+
``` sh
28+
<path-to-greengrass-cli-executable> deployment create --recipeDir ./recipes --artifactDir ./artifacts --merge "com.amazon.RpcTest=1.0.0"
29+
```
30+
31+
Check your nucleus logs and component log for details about the success of the deployment and component execution. See
32+
the [AWS Greengrass Documentation](https://docs.aws.amazon.com/greengrass/v2/developerguide) for more
33+
details about Greengrass components, Greengrass IPC, and the Greengrass CLI.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
import {eventstream_rpc, greengrasscoreipc} from 'aws-iot-device-sdk-v2';
7+
import {once} from "events";
8+
import {toUtf8} from "@aws-sdk/util-utf8-browser";
9+
10+
type Args = { [index: string]: any };
11+
12+
const yargs = require('yargs');
13+
14+
yargs.command('*', false, (yargs: any) => {
15+
}, main).parse();
16+
17+
async function main(argv: Args) {
18+
try {
19+
let client : greengrasscoreipc.Client = greengrasscoreipc.createClient();
20+
21+
await client.connect();
22+
23+
await client.subscribeToIoTCore({
24+
topicName: "hello/world",
25+
qos: greengrasscoreipc.model.QOS.AT_LEAST_ONCE
26+
}).on("message", (message: greengrasscoreipc.model.IoTCoreMessage) => {
27+
if (message.message) {
28+
console.log(`Message received on topic '${message.message.topicName}': '${toUtf8(new Uint8Array(message.message.payload as ArrayBuffer))}'`);
29+
}
30+
}).activate();
31+
32+
setInterval(async () => {
33+
await client.publishToIoTCore({
34+
topicName: "hello/world",
35+
payload: "Hello from a component!",
36+
qos : greengrasscoreipc.model.QOS.AT_LEAST_ONCE
37+
});
38+
}, 10000);
39+
40+
await once(client, greengrasscoreipc.Client.DISCONNECTION);
41+
42+
await client.close();
43+
} catch (err) {
44+
console.log("Aw shucks: " + (err as eventstream_rpc.RpcError) .toString());
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "gg_ipc",
3+
"version": "1.0.0",
4+
"description": "NodeJS IoT SDK v2 GG IPC Sample",
5+
"homepage": "https://github.com/aws/aws-iot-device-sdk-js-v2",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/aws/aws-iot-device-sdk-js-v2.git"
9+
},
10+
"contributors": [
11+
"AWS SDK Common Runtime Team <[email protected]>"
12+
],
13+
"license": "Apache-2.0",
14+
"main": "./dist/index.js",
15+
"scripts": {
16+
"tsc": "tsc",
17+
"prepare": "npm run tsc"
18+
},
19+
"devDependencies": {
20+
"@types/node": "^10.17.50",
21+
"typescript": "^4.7.4"
22+
},
23+
"dependencies": {
24+
"aws-iot-device-sdk-v2": "^1.12.0",
25+
"@aws-sdk/util-utf8-browser": "^3.109.0",
26+
"yargs": "^16.2.0"
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
// "allowJs": true, /* Allow javascript files to be compiled. */
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
"declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
"sourceMap": true, /* Generates corresponding '.map' file. */
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "./dist", /* Redirect output structure to the directory. */
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "removeComments": false, /* Do not emit comments to output. */
18+
// "noEmit": true, /* Do not emit outputs. */
19+
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
20+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22+
/* Strict Type-Checking Options */
23+
"strict": true, /* Enable all strict type-checking options. */
24+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
25+
"strictNullChecks": true, /* Enable strict null checks. */
26+
"strictFunctionTypes": true, /* Enable strict checking of function types. */
27+
"strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
28+
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
29+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
30+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
31+
/* Additional Checks */
32+
"noUnusedLocals": true, /* Report errors on unused locals. */
33+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
34+
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
35+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
36+
/* Module Resolution Options */
37+
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
38+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
39+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
40+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
41+
// "typeRoots": [], /* List of folders to include type definitions from. */
42+
// "types": [], /* Type declaration files to be included in compilation. */
43+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
44+
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
45+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
46+
/* Source Map Options */
47+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
48+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
49+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
50+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
51+
/* Experimental Options */
52+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
53+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
54+
},
55+
"include": [
56+
"*.ts"
57+
],
58+
"exclude": [
59+
"node_modules",
60+
"dist"
61+
]
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"RecipeFormatVersion": "2020-01-25",
3+
"ComponentName": "com.amazon.RpcTest",
4+
"ComponentVersion": "1.0.0",
5+
"ComponentDescription": "A simple component demonstrating GG RPC in Javascript",
6+
"ComponentPublisher": "Amazon",
7+
"ComponentConfiguration": {
8+
"DefaultConfiguration": {
9+
"accessControl": {
10+
"aws.greengrass.ipc.mqttproxy": {
11+
"com.amazon.RcpTest:mqttproxy:1": {
12+
"policyDescription": "Allows access to everything",
13+
"operations": [
14+
"*"
15+
],
16+
"resources": [
17+
"*"
18+
]
19+
}
20+
}
21+
}
22+
}
23+
},
24+
"Manifests": [
25+
{
26+
"Platform": {
27+
"os": "linux"
28+
},
29+
"Lifecycle": {
30+
"Run": "node {artifacts:path}/dist/index.js"
31+
}
32+
},
33+
{
34+
"Platform": {
35+
"os": "windows"
36+
},
37+
"Lifecycle": {
38+
"Run": "node {artifacts:path}/dist/index.js"
39+
}
40+
}
41+
]
42+
}

0 commit comments

Comments
 (0)