Skip to content

Instantly share code, notes, and snippets.

@nachoab
nachoab / resource.yml
Created March 2, 2017 12:31
Cloud Formation: Create API Gateway endpoint with HTTP Integration, passing cognito user [Serverless]
# Create 'foo/bar' private endpoint on API Gateway, with POST method using HTTP integration
# Your APIG foo/bar endpoint will validate the request IAM session and if succeds, pass the request to your endpoint passing all data received including the user session
# It passes request headers, path, querystring, body and context (cognito user is here) to the endpoint as the body payload
ApiGatewayResourceFoo:
Type: AWS::ApiGateway::Resource
Properties:
PathPart: foo
ParentId:
@nachoab
nachoab / aws-cloudwatch-console-delete-log-groups
Created February 2, 2017 10:53
Deletes multiple cloud watch log groups on the AWS console UI filtering by name regexp. Without doing clicks. Useful for serverless migrating to auto create log groups
var nextPage = () => {
return new Promise((resolve, reject) => {
console.log('Go to next page ...');
const disabledIcon = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAXCAYAAAARIY8tAAABVklEQVR42u1UsUrDUBStiyAoKAh+gn6Bk//gqKOOgpvgKDg5OaaFJE1K0iRNSJo2bSIdYhKIJehixoyd+wVS0+t5/YW8ReiFx+Pd4Z5z7j33tVrb2IbjOKeKonwbhnHJvfhwOLwAwHKxWFAQBD+WZV1xBQDrzzAMKc9zqqqKgayQu+EGMB6PT3RdL6GCZrMZlWVJyP32er07biCTyeQYBb80TaPRaERFUbC7liTpgRuI7/uH3W73A8OmwWBAWZYxJbUoik/cQARB2O90OjGKUr/fpyRJKIqiGvkXXnbdbbfbPlOhqiqZpklwGQFAaFx8Pp/voedvcBDBqpsjy/Iaal6JaKepkw7AOnVdd8PY8zzC0NcAeG7MfDqdHsE9BW7Wb2I7gfcaAI9c+o5i74jNQOM4Zn2vsRf3PO15btv2Mk1TwpBXsOgt9/8IrM+wAxXUXG+//v8Zf/3P6XuKEbAtAAAAAElFTkSuQmCC"
const nextImg = document.querySelector('#gwt-debug-pager td:last-child img');
if (nextImg.src !== disabledIcon) {
nextImg.click();
setTimeout(resolve, 1000);
@nachoab
nachoab / s3-aws-policy
Created November 14, 2016 13:19
AWS S3 user folder policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Federated": "cognito-identity.amazonaws.com" },
"Action": ["s3:ListBucket"],
"Resource": ["arn:aws:s3:::BUCKET_NAME"],
"Condition": {"StringLike": {"s3:prefix": ["${cognito-identity.amazonaws.com:sub}/*"]}}
},
@nachoab
nachoab / serverless-auth-extension-plugin
Created October 3, 2016 21:30
adds the posibility to configure AWS_IAM and "Invoke with caller credentials" for your API Gateway endpoints
'use strict';
/**
* Adds the posibility to configure AWS_IAM for your API Gateway endpoints
* and "Invoke with caller credentials"
*
* Usage:
*
* myFuncGetItem:
<!--
TO USE THIS client:
- Go to the google developer console and get your client id. This is pretty
well documented somewhere else. Use your localhost(:port)? as url to work in
your local as always.
- Go to AWS and create a new Federated identity pool
* Associate an Authenticated role and Unauthenticated role to the pool
At least you need cognito-identity and apigateway, edit this for your needs
@nachoab
nachoab / cognito-records-example.js
Created September 21, 2016 12:49
lambda udpate records from a google user using cognito
module.exports.auth = (event, context, callback) => {
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId,
Logins: {
'accounts.google.com': event.id_token
}
});
AWS.config.credentials.get(() =>{
if (!AWS.config.credentials.accessKeyId) {
@nachoab
nachoab / routes.js
Created July 12, 2016 10:43
routes
var rendererOptions = {
draggable: true,
polylineOptions: {
strokeColor: "#FF0000"
}
};
var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
var directionsService = new google.maps.DirectionsService();
var geocoder;
var map;
@nachoab
nachoab / usage.html
Last active August 29, 2015 13:57
Avatar google style for Facebook and Google
<user-avatar id="my-ids" class="my-classes" user="userObject"></user-avatar>