Skip to content

Instantly share code, notes, and snippets.

View tomas-chudjak's full-sized avatar

Tomas Chudjak tomas-chudjak

View GitHub Profile
@tomas-chudjak
tomas-chudjak / facebook-share-thumbnails-nuxt-spa-aws-cloudfront.js
Created January 5, 2023 08:32
AWS Lambda @edge function to generate og:meta tags for facebook
'use strict';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const https = require('https');
export const handler = async(event, context, callback) => {
let content = "";
let userAgent = false;
@tomas-chudjak
tomas-chudjak / cdn-invalidation.sh
Created July 9, 2022 13:06
AWS Cloudfront invalidation script with status waiting method
#!/bin/bash
#================================================================
# HEADER
#================================================================
#% SYNOPSIS
#+ ${SCRIPT_NAME} --distributionId "argument" --path "argument" [--help]
#%
#% DESCRIPTION
#% Function to run AWS CDN invalidation and finishes when invalidation status is set to Completed. Invalidation path is set to '/*' by default.
@tomas-chudjak
tomas-chudjak / remote_script.sh
Last active April 17, 2023 13:07
Bash utility AWS Run Command
#!/bin/bash
#================================================================
# HEADER
#================================================================
#% SYNOPSIS
#+ ${SCRIPT_NAME} --tagName "argument" --tagValue "argument" --scriptFile "argument" --command "argument" --timeout "argument" [--comment] "argument" [--help] [--version]
#%
#% DESCRIPTION
#% Helper function for running external shell scripts on multiple instances with AWS SSM.
@tomas-chudjak
tomas-chudjak / parse-aws-cognito-token-with-go.go
Last active February 16, 2024 15:39
How to parse and validate AWS Cognito token with go
// AWS Cognito public keys are available at address:
// https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json
publicKeysURL := "https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json"
// Start with downloading public keys information
// The .Fetch method is used from https://github.com/lestrrat-go/jwx package
publicKeySet, err := jwk.Fetch(publicKeysURL)
if err != nil{
log.Printf("failed to parse key: %s", err)
}
@tomas-chudjak
tomas-chudjak / tasks.json
Last active May 6, 2020 07:51
VSCode task to upload Hugo's public/ folder to s3 bucket
{
"version": "2.0.0",
"tasks": [
{
"label": "S3 deploy",
"type": "shell",
"command": "hugo --minify && aws s3 sync public/ ${input:s3bucket} --delete --exclude \"*css\" --exclude \"*.js\" --exclude \"*.png\" --exclude \"*.jpg\" --exclude \"*.woff\" && echo '--- s3 upload with cache-control: ---' && aws s3 cp public/ ${input:s3bucket} --recursive --exclude \"*\" --include \"*css\" --include \"*.js\" --include \"*.png\" --include \"*.jpg\" --include \"*.webp\" --include \"*.woff\" --cache-control \"max-age=31536000\"",
"group": "build",
"problemMatcher": []
},