Skip to content

Commit 14d8efe

Browse files
author
aws
committed
Release of Version 1.6.0
1 parent 77c1d98 commit 14d8efe

File tree

93 files changed

+68556
-2990
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+68556
-2990
lines changed

aws-greengrass-core-sdk/index.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
/*
2-
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*/
4-
exports.GreengrassInterfaceVersion = '1.4';
5-
exports.Lambda = require('./lambda');
6-
exports.IotData = require('./iotdata');
7-
exports.SecretsManager = require('./secretsmanager');
4+
exports.GreengrassInterfaceVersion = '1.5';
5+
6+
/**
7+
* @namespace aws-greengrass-core-sdk
8+
*/
9+
10+
const fail = (name, error) => {
11+
console.error(`Unable to load aws-greengrass-core-sdk.${name} due to: `, error);
12+
};
13+
14+
try {
15+
exports.Lambda = require('./lambda');
16+
} catch (e) {
17+
fail('Lambda', e);
18+
}
19+
try {
20+
exports.IotData = require('./iotdata');
21+
} catch (e) {
22+
fail('IotData', e);
23+
}
24+
try {
25+
exports.SecretsManager = require('./secretsmanager');
26+
} catch (e) {
27+
fail('SecretsManager', e);
28+
}
29+
try {
30+
exports.StreamManager = require('./stream-manager');
31+
} catch (e) {
32+
fail('StreamManager', e);
33+
}

aws-greengrass-core-sdk/iotdata.js

Lines changed: 97 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,66 @@
22
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*/
44

5-
const Buffer = require('buffer').Buffer;
5+
const { Buffer } = require('buffer');
66

7+
const GreengrassCommon = require('aws-greengrass-common-js');
78
const Lambda = require('./lambda');
89
const Util = require('./util');
9-
const GreengrassCommon = require('aws-greengrass-common-js');
10-
11-
const envVars = GreengrassCommon.envVars;
12-
const MY_FUNCTION_ARN = envVars.MY_FUNCTION_ARN;
13-
const SHADOW_FUNCTION_ARN = envVars.SHADOW_FUNCTION_ARN;
14-
const ROUTER_FUNCTION_ARN = envVars.ROUTER_FUNCTION_ARN;
1510

11+
const { envVars } = GreengrassCommon;
12+
const { MY_FUNCTION_ARN } = envVars;
13+
const { SHADOW_FUNCTION_ARN } = envVars;
14+
const { ROUTER_FUNCTION_ARN } = envVars;
15+
16+
/**
17+
* Constructs a service interface object. Each API operation is exposed as a function on service.
18+
*
19+
* @class
20+
* @memberOf aws-greengrass-core-sdk
21+
*
22+
* @example <caption>Sending a Request Using IotData</caption>
23+
* var iotdata = new GG.IotData();
24+
* iotdata.getThingShadow(params, function (err, data) {
25+
* if (err) console.log(err, err.stack); // an error occurred
26+
* else console.log(data); // successful response
27+
* });
28+
*/
1629
class IotData {
30+
/**
31+
* Constructs a service object. This object has one method for each API operation.
32+
*
33+
* @example <caption>Constructing a IotData object</caption>
34+
* var iotdata = new GG.IotData();
35+
*/
1736
constructor() {
1837
this.lambda = new Lambda();
1938
}
2039

40+
/**
41+
* Called when a response from the service is returned.
42+
*
43+
* @callback iotDataCallback
44+
* @param err {Error} The error object returned from the request. Set to <tt>null</tt> if the request is successful.
45+
* @param data {Object} The de-serialized data returned from the request. Set to <tt>null</tt> if a request error occurs.
46+
* @param data.payload {Buffer|TypedArray|Blob|String} The state information in JSON format
47+
*/
48+
/**
49+
* Gets the thing shadow for the specified thing.
50+
*
51+
* @param params {Object}
52+
* @param params.thingName {String} The name of the thing.
53+
* @param callback {iotDataCallback} The callback.
54+
*
55+
* @example <caption>Calling the getThingShadow operation</caption>
56+
* var params = {
57+
* thingName: 'STRING_VALUE' // required
58+
* };
59+
* iotdata.getThingShadow(params, function(err, data) {
60+
* if (err) console.log(err, err.stack); // an error occurred
61+
* else console.log(data); // successful response
62+
* });
63+
*/
2164
getThingShadow(params, callback) {
22-
/*
23-
* Call shadow lambda to obtain current shadow state.
24-
* @param {object} params object contains parameters for the call
25-
* REQUIRED: 'thingName' the name of the thing
26-
*/
2765
const thingName = Util.getParameter(params, 'thingName');
2866
if (thingName === undefined) {
2967
callback(new Error('"thingName" is a required parameter.'), null);
@@ -34,13 +72,25 @@ class IotData {
3472
this._shadowOperation('get', thingName, payload, callback);
3573
}
3674

75+
/**
76+
* Updates the thing shadow for the specified thing.
77+
*
78+
* @param params {Object}
79+
* @param params.thingName {String} The name of the thing.
80+
* @param params.payload {String} The state information as a JSON string.
81+
* @param callback {iotDataCallback} The callback.
82+
*
83+
* @example <caption>Calling the updateThingShadow operation</caption>
84+
* var params = {
85+
* payload: 'Proper JSON data', // required
86+
* thingName: 'STRING_VALUE' // required
87+
* };
88+
* iotdata.updateThingShadow(params, function(err, data) {
89+
* if (err) console.log(err, err.stack); // an error occurred
90+
* else console.log(data); // successful response
91+
* });
92+
*/
3793
updateThingShadow(params, callback) {
38-
/*
39-
* Call shadow lambda to update current shadow state.
40-
* @param {object} params object contains parameters for the call
41-
* REQUIRED: 'thingName' the name of the thing
42-
* 'payload' the state information in JSON format
43-
*/
4494
const thingName = Util.getParameter(params, 'thingName');
4595
if (thingName === undefined) {
4696
callback(new Error('"thingName" is a required parameter.'), null);
@@ -56,12 +106,14 @@ class IotData {
56106
this._shadowOperation('update', thingName, payload, callback);
57107
}
58108

109+
/**
110+
* Call shadow lambda to delete the shadow state.
111+
*
112+
* @param params {Object}
113+
* @param params.thingName {String} The name of the thing whose shadow should be deleted.
114+
* @param callback {iotDataCallback} The callback.
115+
*/
59116
deleteThingShadow(params, callback) {
60-
/*
61-
* Call shadow lambda to delete the shadow state.
62-
* @param {object} params object contains parameters for the call
63-
* REQUIRED: 'thingName' the name of the thing
64-
*/
65117
const thingName = Util.getParameter(params, 'thingName');
66118
if (thingName === undefined) {
67119
callback(new Error('"thingName" is a required parameter.'), null);
@@ -72,14 +124,27 @@ class IotData {
72124
this._shadowOperation('delete', thingName, payload, callback);
73125
}
74126

127+
/**
128+
* Publishes a message within Greengrass.
129+
*
130+
* @param params {Object}
131+
* @param params.topic {String} The name of the MQTT topic.
132+
* @param params.payload {Buffer|TypedArray|Blob|String} The payload to be sent.
133+
* @param params.queueFullPolicy {'AllOrError'|'BestEffort'} Specify whether to enforce message delivery to all destinations. Options are 'AllOrError' and 'BestEffort'. Defaults to 'BestEffort' when omitted.
134+
* @param callback {iotDataCallback} The callback.
135+
*
136+
* @example <caption>Calling the publish operation</caption>
137+
* var params = {
138+
* topic: 'STRING_VALUE', // required
139+
* payload: new Buffer('...') || 'STRING_VALUE',
140+
* queueFullPolicy: 'AllOrError' || 'BestEffort'
141+
* };
142+
* iotdata.publish(params, function(err, data) {
143+
* if (err) console.log(err, err.stack); // an error occurred
144+
* else console.log(data); // successful response
145+
* });
146+
*/
75147
publish(params, callback) {
76-
/*
77-
* Publishes state information.
78-
* @param {object} params object contains parameters for the call
79-
* REQUIRED: 'topic' the topic name to be published
80-
* 'payload' the state information in JSON format
81-
* OPTIONAL: 'queueFullPolicy' the policy for GGC to take when its internal queue is full
82-
*/
83148
const topic = Util.getParameter(params, 'topic');
84149
if (topic === undefined) {
85150
callback(new Error('"topic" is a required parameter'), null);
@@ -131,9 +196,9 @@ class IotData {
131196

132197
this.lambda.invoke(invokeParams, (err, data) => {
133198
if (err) {
134-
callback(err, null); // an error occurred
199+
callback(err, null); // an error occurred
135200
} else {
136-
callback(null, data); // successful response
201+
callback(null, data); // successful response
137202
}
138203
});
139204
}

aws-greengrass-core-sdk/lambda.js

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,94 @@
22
* Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*/
44

5-
const Util = require('./util');
65
const IPCClient = require('aws-greengrass-ipc-sdk-js');
76
const GreengrassCommon = require('aws-greengrass-common-js');
8-
const logging = require('aws-greengrass-common-js').logging;
7+
const { logging } = require('aws-greengrass-common-js');
8+
const Util = require('./util');
99

10-
const AUTH_TOKEN = GreengrassCommon.envVars.AUTH_TOKEN;
10+
const { AUTH_TOKEN } = GreengrassCommon.envVars;
1111

1212
const logger = new logging.LocalWatchLogger();
1313

14+
/**
15+
* Constructs a service interface object. Each API operation is exposed as a function on service.
16+
* @class
17+
* @memberOf aws-greengrass-core-sdk
18+
*/
1419
class Lambda {
20+
/**
21+
* Constructs a service object. This object has one method for each API operation.
22+
*
23+
* @example <caption>Constructing a Lambda object</caption>
24+
* var lambda = new GG.Lambda();
25+
*/
1526
constructor() {
1627
this.ipc = new IPCClient(AUTH_TOKEN);
1728
}
1829

30+
/**
31+
* Called when a response from the service is returned.
32+
*
33+
* @callback lambdaCallback
34+
* @param err {Error} The error object returned from the request. Set to <tt>null</tt> if the request is successful.
35+
* @param data {Object} The de-serialized data returned from the request. Set to <tt>null</tt> if a request error occurs.
36+
* @param data.StatusCode {Integer} The HTTP status code will be in the 200 range for successful request. For the <tt>RequestResponse</tt> invocation type this status code will be 200.
37+
* For the <tt>Event</tt> invocation type this status code will be 202.
38+
* @param data.FunctionError {String} Indicates whether an error occurred while executing the Lambda function. If an error occurred this field will have one of two values; <tt>Handled</tt> or <tt>Unhandled</tt>.
39+
* <tt>Handled</tt> errors are errors that are reported by the function while the Unhandled errors are those detected and reported by AWS Lambda.
40+
* <tt>Unhandled</tt> errors include out of memory errors and function timeouts. For information about how to report an <tt>Handled</tt> error,
41+
* see <a href="http://docs.aws.amazon.com/lambda/latest/dg/programming-model.html">Programming Model</a>.
42+
* @param data.Payload {Buffer|TypedArray|Blob|String} It is the result returned by the Lambda function. This is present only if the invocation type is <tt>RequestResponse</tt>.
43+
* <br/>In the event of a function error this field contains a message describing the error. For the <tt>Handled</tt> errors the Lambda function will report this message. For <tt>Unhandled</tt> errors AWS Lambda reports the message.
44+
*/
45+
46+
/**
47+
* Invokes a specific Lambda function.<br/>
48+
* In Greengrass, version of the Lambda which you would like to invoke needs to be provided.
49+
*
50+
* @param params {Object}
51+
* @param params.FunctionName {String} The Lambda function name. You can specify Amazon Resource Name (ARN) of the function (for example, <tt>arn:aws:lambda:us-west-2:account-id:function:ThumbNail</tt>).
52+
* @param params.InvocationType {String?} By default, the <tt>Invoke</tt> API assumes <tt>RequestResponse</tt> invocation type.
53+
* You can optionally request asynchronous execution by specifying <tt>Event</tt> as the <tt>InvocationType</tt>. Possible values include:
54+
* <ul><li>"Event"</li><li>"RequestResponse"</li></ul>
55+
* @param params.ClientContext {String?} Using the <tt>ClientContext</tt> you can pass client-specific information to the Lambda function you are invoking.
56+
* You can then process the client information in your Lambda function as you choose through the context variable.
57+
* For an example of a <tt>ClientContext</tt> JSON, see the main page or an example folder for an example.
58+
* <br/>The <tt>ClientContext</tt> JSON must be base64-encoded.
59+
* @param params.Payload {Buffer|TypedArray|Blob|String} Payload that you want to provide to your Lambda function as input.
60+
* @param params.Qualifier {String?} You can use this optional parameter to specify a Lambda function version if it was not included in the FunctionName field.
61+
* If you specify a function version, the API uses the qualified function ARN to invoke a specific Lambda function.
62+
* <br/>If you don't provide this parameter, then the API uses the FunctionName field only. If it does not have a version number of the target lambda, the call will fail.
63+
* @param callback {lambdaCallback} The callback.
64+
*
65+
* @example <caption>To invoke a Lambda function</caption>
66+
* //This operation invokes a Lambda function
67+
*
68+
* var params = {
69+
* ClientContext: "MyApp",
70+
* FunctionName: "MyFunction",
71+
* InvocationType: "Event",
72+
* Payload: <json | binary>,
73+
* Qualifier: "1"
74+
* };
75+
* lambda.invoke(params, function(err, data) {
76+
* if (err) console.log(err, err.stack); // an error occurred
77+
* else console.log(data); // successful response
78+
* });
79+
*
80+
* @example <caption>Calling the invoke operation</caption>
81+
* var params = {
82+
* FunctionName: 'STRING_VALUE', // required
83+
* ClientContext: 'STRING_VALUE',
84+
* InvocationType: Event | RequestResponse,
85+
* Payload: <json | binary>,
86+
* Qualifier: 'STRING_VALUE'
87+
* };
88+
* lambda.invoke(params, function(err, data) {
89+
* if (err) console.log(err, err.stack); // an error occurred
90+
* else console.log(data); // successful response
91+
* });
92+
*/
1993
invoke(params, callback) {
2094
const functionName = Util.getParameter(params, 'FunctionName');
2195
if (functionName === undefined) {
@@ -67,11 +141,12 @@ class Lambda {
67141
// GGC v1.9.0 or newer
68142
functionArn = GreengrassCommon.buildFunctionArn(
69143
arnFields.unqualifiedArn,
70-
finalQualifier);
144+
finalQualifier,
145+
);
71146
} else {
72147
// older version of GGC
73-
throw new Error('Function buildFunctionArn not found. buildFunctionArn is introduced in GGC v1.9.0. ' +
74-
'Please check your GGC version.');
148+
throw new Error('Function buildFunctionArn not found. buildFunctionArn is introduced in GGC v1.9.0. '
149+
+ 'Please check your GGC version.');
75150
}
76151

77152
// verify client context is base64 encoded
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "aws-greengrass-core-sdk",
3+
"version": "1.6.0",
4+
"main": "index.js",
5+
"dependencies": {
6+
"cbor": "5.0.1"
7+
},
8+
"license": "Apache-2.0",
9+
"author": {
10+
"name": "Amazon Web Services",
11+
"url": "https://aws.amazon.com"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "git://github.com/aws/aws-greengrass-core-sdk-js"
16+
}
17+
}

0 commit comments

Comments
 (0)