Skip to content

Instantly share code, notes, and snippets.

View dave-malone's full-sized avatar

Dave Malone dave-malone

  • Amazon Web Services
  • Tampa, FL
View GitHub Profile
@dave-malone
dave-malone / instructions.md
Last active December 7, 2018 21:02
Changes required to use the Greengrass sample within aws-iot-device-sdk-python

Modify your Thing's policy to allow it to connect to the Greengrass Discovery service:

  • Secure -> Policies
  • Select your Thing's Policy
  • Edit your Thing's Policy document, and Save as a new version. See my example policy, specifically the addition of the greengrass:Discover statement at the bottom of the policy:
{
  "Version": "2012-10-17",
  "Statement": [
@dave-malone
dave-malone / greengrass-lambda-invoke-another-lambda.py
Created April 16, 2019 14:10
Example AWS IoT Greengrass Lambda invoking another Lambda
#
# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# greengrassHelloWorld.py
# Demonstrates a simple publish to a topic using Greengrass core 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. The handler
@dave-malone
dave-malone / bundle-and-deploy-lambda.sh
Created April 16, 2019 14:20
An example of how to automate Lamba code updates, versions, and aliases
rm hello_world_python_lambda.zip
zip -r hello_world_python_lambda.zip greengrasssdk greengrassHelloWorld.py
update_lambda_result=$(aws lambda update-function-code \
--function-name Greengrass_HelloWorld \
--zip-file fileb://hello_world_python_lambda.zip \
--publish)
latest_lambda_version=$(echo "$update_lambda_result" | jq -r '.Version')
@dave-malone
dave-malone / aws-iot-paho-client-multi-subscription-single-subscription-request.py
Created June 26, 2019 23:01
Demo Python program illustrating connecting to AWS IoT Core and establishing multiple subscriptions in a single Subscription request
from __future__ import print_function
import sys
import ssl
import time
import datetime
import logging, traceback
import paho.mqtt.client as mqtt
IoT_protocol_name = "x-amzn-mqtt-ca"
aws_iot_endpoint = "a1tq0bx5we8tnk-ats.iot.us-east-1.amazonaws.com"
const AWS = require('aws-sdk')
AWS.config.region = process.env.AWS_REGION
const kinesisvideo = new AWS.KinesisVideo({
})
function getStreamingSessionURL(){
return new Promise((resolve, reject) => {
var getEndpointParams = {
@dave-malone
dave-malone / multi-attribute-things.md
Last active August 14, 2024 13:25
An example of how to create AWS IoT Things with more than three attributes
THING_TYPE_NAME=multi-attribute-type
THING_NAME=multi-attribute-thing
DYNAMIC_GROUP_NAME=multi-attribute-dynamic-group

aws iot create-thing-type --thing-type-name $THING_TYPE_NAME

aws iot create-thing \
  --thing-name $THING_NAME \
 --thing-type-name $THING_TYPE_NAME \
@dave-malone
dave-malone / gist:9ddb7fed7405d09a158bfb3fcfe258db
Created September 1, 2020 12:53
remount read-only, completely full filesystem
I was unable to free up disk space on my Raspberry Pi recently, and I kept getting a "cannot remove... Read-only file system" error when attempting to run the `rm` command. The following step was necessary prior to then removing uncessary files and freeing up space on the filesystem.
`sudo mount -o remount,rw /`
@dave-malone
dave-malone / dropin.sh
Created September 23, 2020 20:51
Drop into a running Lambda function container on Greengrass
ps aux | grep lambda_runtime
sudo nsenter -t $PID -m /bin/bash
@dave-malone
dave-malone / gg-upgrade.md
Created November 9, 2020 16:23
AWS CLI Commands to upgrade the GG software on a specific GG core

TARGET_ARCHITECTURE=armv7l TARGET_OPERATING_SYSTEM=raspbian S3_URL_SIGNER_ROLE_ARN="arn:aws:iam:::role/AllowAccessToGreengrassOTAUpdateArtifacts" GG_UPDATE_TARGET="arn:aws:iot:us-east-1::thing/<GG_CORE_THING_NAME>"

aws greengrass create-software-update-job
--update-targets-architecture $TARGET_ARCHITECTURE
--update-targets "${GG_UPDATE_TARGET}"
--update-targets-operating-system $TARGET_OPERATING_SYSTEM
--software-to-update core \

@dave-malone
dave-malone / cardboard_cruiser.py
Created November 21, 2020 15:57
cardboard_cruiser.py
import time
import logging
import threading
import atexit
from adafruit_crickit import crickit
format = "%(asctime)s: %(message)s"
logging.basicConfig(format=format, level=logging.INFO, datefmt="%H:%M:%S")
# make two variables for the motors to make code shorter to type