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 / 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"
@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 / 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 / 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 / avro_to_aws_iot.py
Last active November 9, 2018 17:37
A simple Python program to demonstrate submitting an Avro encoded file as a binary payload into AWS IoT Core
from avro.datafile import DataFileWriter
from avro.io import DatumWriter
from AWSIoTPythonSDK.MQTTLib import AWSIoTMQTTClient
import avro.schema
import logging
import time
import os
avro_users_schema_file = "user.avsc"
avro_users_file = "users.avro"
@dave-malone
dave-malone / add-swap.md
Last active October 16, 2018 12:14
Add more swap space to Raspberry Pi
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1

Remove swap space once done

- name: DefaultOktaRoles
baseline_products:
- AWS-Landing-Zone-Account-Vending-Machine
template_file: templates/aws_baseline/aws-landing-zone-default-okta-roles.template
parameter_file: parameters/aws_baseline/aws-landing-zone-default-okta-roles.json
deploy_method: stack_set
@dave-malone
dave-malone / aws-landing-zone-default-okta-roles.json
Created September 21, 2018 16:13
parameters/aws_baseline/aws-landing-zone-default-okta-roles.json
[
{
"ParameterKey": "EnableAdminRole",
"ParameterValue": "true"
},
{
"ParameterKey": "EnablePowerUserRole",
"ParameterValue": "true"
},
{
@dave-malone
dave-malone / aws-landing-zone-default-okta-roles.template
Created September 21, 2018 16:12
templates/aws_baseline/aws-landing-zone-default-okta-roles.template
AWSTemplateFormatVersion: 2010-09-09
Description: Create Okta IDP and default roles on all accounts.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: "Okta SAML IDP"
Parameters:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::{account-id}:role/LandingZoneLambdaRoleADConnector",
"arn:aws:iam::{account-id}:role/AWSCloudFormationStackSetAdministrationRole",
"arn:aws:iam::{account-id}:role/StateMachineLambdaRoleADConnector",