Skip to content

Instantly share code, notes, and snippets.

View prestomation's full-sized avatar

Preston Tamkin prestomation

View GitHub Profile
//Using Document Client
var params = {
Item: {
hashkey: 'key',
boolAttr: true,
listAttr: [1, 'baz', true]
mapAttr: {
foo: 'bar'
}
},
//Using low-level API Client
var params = {
Item: {
hashkey: { "S" : "key"},
boolAttr: { "B" : "true" },
listAttr: { "L" : [{ "N" : 1}, { "S":'baz'}, { B: "true" }]}
mapAttr: {
M : {
"foo": { "S" : "bar"}
}
{
“userId” : {
“S” : “$MY_USER_ID”
},
“accountBalance” : {
“N” : “0”
}
}
var presignIOTMQTTConnection = function(endpoint, credentials) {
//Turn off param validation because of the hackery coming up
var service = new AWS.IotData({endpoint : endpoint, credentials : credentials, paramValidation: false});
//MQTT broker uses a different servicename in the sigv4 algo
service.api.signingName = "iotdevicegateway";
//1. Create a request object for another, sorta similar request
//2. Save off our session token and delete it from the credentials(so it doesn't get signed)
//3. Register to an event in the state machine to adjust the path
/**
* utilities to do sigv4
* @class SigV4Utils
*/
function SigV4Utils() {}
SigV4Utils.getSignatureKey = function (key, date, region, service) {
var kDate = AWS.util.crypto.hmac('AWS4' + key, date, 'buffer');
var kRegion = AWS.util.crypto.hmac(kDate, region, 'buffer');
var kService = AWS.util.crypto.hmac(kRegion, service, 'buffer');
//Turn off param validation because of the hackery coming up
var service = new AWS.IotData({endpoint : "data.iot.us-east-1.amazonaws.com", credentials : credentials, paramValidation : false});
//MQTT broker uses a different servicename in the sigv4 algo
service.api.signingName = "iotdevicegateway";
//Connecting to MQTT isn't actually a published operation.
//soooo Let's copy another GET request for some hackery..
var connect = $.extend(true, {}, service.api.operations.getThingShadow);
//..change the path
Resources:
CrashingLambda:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: >
exports.handler = function(event, context) {
FunctionDoesntExist();
};
Handler: index.handler
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"dynamodb:GetItem",
"dynamodb:BatchGetItem",
"dynamodb:Query",
"dynamodb:PutItem",