Skip to content

Instantly share code, notes, and snippets.

View danilop's full-sized avatar
😀
I am building something!

Danilo Poccia danilop

😀
I am building something!
View GitHub Profile
#!/usr/bin/env python
import boto3
import argparse
from operator import itemgetter
from collections import defaultdict
def nested_defaultdict():
return defaultdict(nested_defaultdict)
@danilop
danilop / template.yaml
Last active February 29, 2024 12:50
Sample AWS SAM Template using Provisioned Concurrency with Application Auto Scaling
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Sample SAM Template using Application Auto Scaling + Provisioned Concurrency
Globals:
Function:
Timeout: 30
@danilop
danilop / runTests.js
Created June 11, 2018 17:40
Run tests on all CLoudFormation resources in the stack
async function runTests() {
let tests = [];
// Unit tests
tests.push(testFunction(functionName)); // With version
// Check all resources in the stack
let resources = await listStackResources(stackId);
@danilop
danilop / listStackResources.js
Last active June 11, 2018 17:34
Return the list of resources in a CloudFormation Stack
async function listStackResources(stackName) {
console.log("Calling AWS CloudFormation to list Resources for Stack " + stackName);
return await manageApiPagination(CloudFormation, 'listStackResources', {
StackName: stackName
}, 'StackResourceSummaries');
}
@danilop
danilop / deploy.sh
Last active June 11, 2018 15:40
AWS CLI package/deploy of a SAM template for a serverless application using safe deployments
aws cloudformation package -s3-bucket <YOUR_BUCKET> -s3-prefix packages \
-template-file template.yaml -output-template-file packaged.yaml
aws cloudformation deploy -template-file packaged.yaml \
-stack-name EvolutionaryDeployment -capabilities CAPABILITY_IAM
@danilop
danilop / GreetingsAPI.js
Last active May 7, 2023 15:36
Sample AWS Lambda function exposing the same business logic using the Amazon API Gateway of the Node.js Express framework.
"use strict";
console.log('Loading function');
// Your business logic
function greetingsFor(name) {
console.log('name: ', name);
if ((name == undefined) || (name == '')) {
name = 'World';
}
@danilop
danilop / greetingsOnDemand.js
Last active April 3, 2018 13:00
Sample AWS Lambda function showing how to split your business logic from the event handler.
"use strict";
console.log('Loading function');
// Your business logic
function greetingsFor(name) {
console.log('name: ', name);
if ((name == undefined) || (name == '')) {
name = 'World';
}
@danilop
danilop / gist:6d49e2b6507f748a00a9
Created November 11, 2015 12:33
Amazon EC2 - user data to automatically mount an Amazon EFS file system at boot (Linux)
#cloud-config
package_upgrade: true
packages:
- nfs-utils
- httpd
- php
runcmd:
- echo "$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).FILE_SYSTEM_ID.efs.us-west-2.amazonaws.com:/ /var/www/html/efs nfs4 defaults" >> /etc/fstab
- mkdir /var/www/html/efs
- mount -a
@danilop
danilop / gist:d4ff43835e469043e95e
Last active August 7, 2020 09:29
Amazon S3 redirection rule to send every "miss" (HTTP 404) to the domain root
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>danilop.net</HostName>
<ReplaceKeyWith/>
</Redirect>
</RoutingRule>