Skip to content

Instantly share code, notes, and snippets.

View daaru00's full-sized avatar
🐢

Fabio Gollinucci daaru00

🐢
View GitHub Profile
@daaru00
daaru00 / template.yaml
Created March 4, 2024 08:24
API Gateway mocked API example template
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Mocked HTTP API
Parameters:
ThrottlingRateLimit:
Type: Number
Description: The rate limit for the mock API.
Default: 1
@daaru00
daaru00 / template.yml
Created July 8, 2021 14:44
A SAM template that describe an Amazon CloudFront distribution that serve a static website from an S3 Bucket.
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
# Template Information
Description: "Personal Website"
# Template Parameters
@daaru00
daaru00 / session.mjs
Created February 22, 2024 11:55
Session management using encrypted server-only cookie
import crypto from 'crypto'
const COOKIE_NAME = 'session'
const COOKIE_GET_HEADER = 'Cookie'
const COOKIE_SET_HEADER = 'Set-Cookie'
const ENCRYPTION_ALGORITHM = 'aes-256-cbc'
/**
* Decode session from cookie header
*
@daaru00
daaru00 / opcache-clean.sh
Last active December 15, 2023 04:10
Reset PHP OPcache cache from command line
#!/bin/bash
WEBDIR=/var/www/html/
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
echo "<?php opcache_reset(); ?>" > ${WEBDIR}${RANDOM_NAME}.php
curl http://localhost/${RANDOM_NAME}.php
rm ${WEBDIR}${RANDOM_NAME}.php
echo "cache reset"
@daaru00
daaru00 / authorizer.js
Last active July 12, 2023 12:45
Lambda authorizer to check OAuth2 authorization token
const https = require('https');
const jose = require('node-jose');
const region = process.env.COGNITO_REGION;
const userpool_id = process.env.COGNITO_USER_POOL_ID;
const app_client_id = process.env.COGNITO_CLIENT_ID;
const keys_url = 'https://cognito-idp.' + region + '.amazonaws.com/' + userpool_id + '/.well-known/jwks.json';
/**
* Lambda handler
@daaru00
daaru00 / template.yml
Created June 15, 2021 08:47
A SAM template that describe an Amazon CloudFront distribution that redirect all request to a specific URL using a CloudFront Function
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
# Template Information
Description: "Website redirect"
# Template Parameters
@daaru00
daaru00 / template.yaml
Last active October 3, 2022 19:24
Use EventBridge events to execute code when the CloudFormation stack itself is created
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${StackCreatedFunction}
RetentionInDays: 7
@daaru00
daaru00 / index.js
Created August 5, 2022 14:01
X-Ray integration with Lambda
const AWSXRay = require('aws-xray-sdk')
AWSXRay.setLogger(console)
/**
* Lambda handler
*/
exports.handler = async (event) => {
console.log(JSON.stringify(event))
@daaru00
daaru00 / useEvents.js
Last active December 28, 2021 11:28
Vue 3 composition API events bus implementation
const eventBus = new Comment('global-event-bus');
const listeners = {};
export const EVENT_NAME = 'MyEventName';
export default function () {
/**
* @param {string} event
* @param {function} callback
* @returns {number} index
@daaru00
daaru00 / template.yml
Created July 8, 2021 14:51
A SAM template that describe an AWS CodeBuild pipeline that build a static website and deploy it to an S3 Bucket and invalidate the CloudFront distribution.
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
# Template Information
Description: "Personal Website Deploy Pipeline"
# Template Parameters