Skip to content

Commit

Permalink
Release of Version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aws committed Jun 12, 2019
1 parent bdd489f commit 4fd6cd8
Show file tree
Hide file tree
Showing 28 changed files with 3,336 additions and 254 deletions.
6 changes: 0 additions & 6 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

4 changes: 0 additions & 4 deletions CODE_OF_CONDUCT.md

This file was deleted.

61 changes: 0 additions & 61 deletions CONTRIBUTING.md

This file was deleted.

375 changes: 201 additions & 174 deletions LICENSE

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
AWS Greengrass Core SDK Js
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
AWS Greengrass Core SDK for JavaScript
Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.

This product includes software developed at
Amazon Web Services, Inc. (http://aws.amazon.com/).

1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Instructions can be found under manual/index.html
7 changes: 0 additions & 7 deletions README.md

This file was deleted.

42 changes: 42 additions & 0 deletions greengrassExamples/HelloWorld/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates a simple publish to a topic using Greengrass Core NodeJS SDK
* This lambda function will retrieve underlying platform information and send
* a hello world message along with the platform information to the topic
* 'hello/world'. The function will sleep for five seconds, then repeat.
* Since the function is long-lived it will run forever when deployed to a
* Greengrass core.
*/

const ggSdk = require('aws-greengrass-core-sdk');

const iotClient = new ggSdk.IotData();
const os = require('os');
const util = require('util');

function publishCallback(err, data) {
console.log(err);
console.log(data);
}

const myPlatform = util.format('%s-%s', os.platform(), os.release());
const pubOpt = {
topic: 'hello/world',
payload: JSON.stringify({ message: util.format('Hello world! Sent from Greengrass Core running on platform: %s using NodeJS', myPlatform) }),
};

function greengrassHelloWorldRun() {
iotClient.publish(pubOpt, publishCallback);
}

// Schedule the job to run every 5 seconds
setInterval(greengrassHelloWorldRun, 5000);

// This is a handler which does nothing for this example
exports.handler = function handler(event, context) {
console.log(event);
console.log(context);
};
13 changes: 13 additions & 0 deletions greengrassExamples/LambdaInvoke/invokee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates how to return a result back to the caller of this lambda
*/

exports.handler = function handler(event, context, callback) {
console.log(event);
console.log(context);
callback(undefined, { result: 'message' });
};
40 changes: 40 additions & 0 deletions greengrassExamples/LambdaInvoke/invokerbinary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates how to invoke another lambda with binary data and receive the value from the call
*/

const ggSdk = require('aws-greengrass-core-sdk');

const lambdaClient = new ggSdk.Lambda();

exports.handler = function handler(event, context) {
console.log(event);
console.log(context);

const cxt = {
custom: {
customData: 'customData',
},
};
const contextString = JSON.stringify(cxt);
const buff = Buffer.from(contextString);
const clientContext = buff.toString('base64');

const params = {
FunctionName: 'arn:<partition>:lambda:<region>:<accountId>:function:<targetFunctionName>:<targetFunctionQualifier>',
InvocationType: 'RequestResponse',
ClientContext: clientContext,
Payload: Buffer.from('payload message', 'utf8'),
};

lambdaClient.invoke(params, (err, data) => {
if (err) {
console.error(err, err.stack);
} else {
console.log(data);
}
});
};
40 changes: 40 additions & 0 deletions greengrassExamples/LambdaInvoke/invokerjson.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates how to invoke another lambda with json data and receive the value from the call
*/

const ggSdk = require('aws-greengrass-core-sdk');

const lambdaClient = new ggSdk.Lambda();

exports.handler = function handler(event, context) {
console.log(event);
console.log(context);

const cxt = {
custom: {
customData: 'customData',
},
};
const contextString = JSON.stringify(cxt);
const buff = Buffer.from(contextString);
const clientContext = buff.toString('base64');

const params = {
FunctionName: 'arn:<partition>:lambda:<region>:<accountId>:function:<targetFunctionName>:<targetFunctionQualifier>',
InvocationType: 'RequestResponse',
ClientContext: clientContext,
Payload: JSON.stringify({ message: 'payload message' }),
};

lambdaClient.invoke(params, (err, data) => {
if (err) {
console.error(err, err.stack);
} else {
console.log(data);
}
});
};
48 changes: 48 additions & 0 deletions greengrassExamples/ShadowOperations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates a shadow operation using Greengrass Core NodeJS SDK
* This lambda function will retrieve underlying platform information and
* update the reported state of 'platform' shadow with that message.
*/

const ggSdk = require('aws-greengrass-core-sdk');

const iotClient = new ggSdk.IotData();
const os = require('os');
const util = require('util');

const myPlatform = util.format('%s-%s', os.platform(), os.release());
const shadowUpdateParams = {
thingName: 'platform',
payload: JSON.stringify({ state: { reported: { platform: myPlatform } } }),
};
const shadowGetParams = {
thingName: 'platform',
};

exports.handler = function handler(event, context) {
console.log(context);

// Update Thing Shadow
console.log('Update Thing Operation');
iotClient.updateThingShadow(shadowUpdateParams, (err, data) => {
if (err) {
console.log(err);
} else {
console.log(data);
}
});

// Get Thing Shadow
console.log('Shadow Get Operation');
iotClient.getThingShadow(shadowGetParams, (err, data) => {
if (err) {
console.log(err);
} else {
console.log(data);
}
});
};
41 changes: 41 additions & 0 deletions greengrassExamples/TES/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
The TES example package contains a Lambda function that, when run,
will attempt to retrieve AWS credentials. The goal of TES is to allow
users to retrieve credentials without having them hard-coded on the
system itself.

Assuming no credentials exist on the system, when the Lambda function
is run, temporary credentials will be sourced from the cloud.

The credential retrieval is retrieved with an incremental backoff
in case of an error. Users must be aware that the retrieval may not
always succeed on the first try and retry should be performed with care.

### SETUP ###
1. Copy the included index.js to your Lambda function.

2. Install aws-sdk by performing "npm install aws-sdk".

3. Unzip the Greengrass Core SDK for NodeJS into node_modules folder.

4. Zip the folder with index.js on the top level.

5. Create a Lambda in the Lambda Console.
Handler: index.handler
Runtime: Node.js 8.10
Timeout: 3s
Role: any basic execution role can be used here

6. Create a group that contains your Greengrass Core and the Lambda
function you've just created.

7. In the Greengrass console, click on the Lambda function and set
the Memory limit is at least 40MB and "Lambda lifecycle" is set to
"Make this function long-lived and keep it running indefinitely".

8. Under Settings page of the group, make sure the Group Role is
set to the role you want to use within Greengrass when
performing actions against AWS.

9. Deploy the latest Greengrass to your device.

10. Local log should display the access key, secret key and session token.
40 changes: 40 additions & 0 deletions greengrassExamples/TES/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*/

/*
* Demonstrates retrieving a Group Role Credential if one is set.
*/

const AWS = require('aws-sdk');
const util = require('util');

const credChain = new AWS.CredentialProviderChain();

// Max retry every 30 seconds to retrieve the credentials
const maxRetryInterval = 30;
// Initially, try with one second retry interval
const initialRetryInterval = 1;

function getCredential(retryInterval) {
const promise = credChain.resolvePromise();

promise.then((creds) => {
console.log(util.format('Access Key: %s\nSecret Key: %s\nSession Key: %s\n', creds.accessKeyId, creds.secretAccessKey, creds.sessionToken));
},
(err) => {
console.log(err);
// Try again with incremental backoff
setTimeout(() => {
getCredential(Math.min(maxRetryInterval, retryInterval * 2));
}, retryInterval);
});
}

getCredential(initialRetryInterval);

// This is a handler which does nothing for this example
exports.handler = function handler(event, context) {
console.log(event);
console.log(context);
};
Loading

0 comments on commit 4fd6cd8

Please sign in to comment.