Skip to content

Instantly share code, notes, and snippets.

View piotrekwitkowski's full-sized avatar

piotrekwitkowski

View GitHub Profile
@piotrekwitkowski
piotrekwitkowski / user-data.sh
Last active July 20, 2023 18:44
User Data script for EC2 to clone and run node app with pm2
#!/bin/bash
sudo yum update -y
sudo yum install -y git nodejs
git -v # Check git version
node -v # Check node version
npm -v # Check npm version
npm i -g pm2
export HOME=/home/ec2-user
pm2 -v # Check pm2 version
@piotrekwitkowski
piotrekwitkowski / with-delay.ts
Created August 1, 2023 10:52
Typescript HOC withDelay
const withDelay = async <T,>(delay = 0, callback: () => T) => {
await new Promise(resolve => setTimeout(resolve, delay));
return callback();
}
@piotrekwitkowski
piotrekwitkowski / redirect-behavior.ts
Last active February 14, 2024 22:38
Redirect behavior for CloudFront with CDK and TypeScript
import { Stack } from "aws-cdk-lib";
import { BehaviorOptions, Function, FunctionCode, FunctionEventType } from "aws-cdk-lib/aws-cloudfront";
import { HttpOrigin } from "aws-cdk-lib/aws-cloudfront-origins";
import { join } from "path";
export const getRedirectBehavior = (scope: Stack, id: string, location: string): BehaviorOptions => {
const redirectFilePath = join(__dirname, 'redirect-function.js');
const redirectFunctionCode = FunctionCode.fromFile({ filePath: redirectFilePath });
const redirectFunction = new Function(scope, `${id}-default-redirect-function`, {
code: redirectFunctionCode
@piotrekwitkowski
piotrekwitkowski / template.yaml
Created July 31, 2024 10:12
Lambda function in a CloudFormation template to copy an asset from one bucket to another
S3AssetCopyFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: S3AssetCopy
Handler: index.handler
Role: !GetAtt LambdaExecutionRole.Arn
MemorySize: 4096
Runtime: python3.12
Timeout: 30
Code: