Skip to content

Instantly share code, notes, and snippets.

View filipeandre's full-sized avatar

Filipe Ferreira filipeandre

  • 22:07 (UTC +01:00)
View GitHub Profile
@atheiman
atheiman / docker-image-share.sh
Created May 21, 2024 01:55
Package and share docker image
# Package docker image to .tar.gz to share to another machine
docker pull alpine
docker save alpine | gzip > alpine.tar.gz
# Load docker image from .tar.gz
docker load < alpine.tar.gz
# Show loaded image
docker image ls alpine
# REPOSITORY TAG IMAGE ID CREATED SIZE
---
Resources:
QueueForPipe:
Type: AWS::SQS::Queue
LambdaServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
@atheiman
atheiman / aws_switch_role_bookmark_generator.py
Last active May 21, 2024 11:59
AWS organization switch role (assume role) bookmark generator - outputs html to stdout that can be saved to a .html file and imported into browser bookmarks.
import boto3
import os
# Environment variables for configuration
role_name = os.environ.get("ROLE_NAME", "OrganizationAccountAccessRole")
include_mgmt = os.environ.get("INCLUDE_MGMT", "true").lower() == "true"
sts = boto3.client("sts")
caller_arn = sts.get_caller_identity()["Arn"]
partition = caller_arn.split(":")[1]
@atheiman
atheiman / security_hub_findings_query.py
Last active May 21, 2024 12:00
Security Hub findings querying and batch updating with boto3. Suppress sample findings (i.e. from GuardDuty "CreateSampleFindings").
#!/usr/bin/env python
import boto3
import json
sechub = boto3.client("securityhub")
sts = boto3.client("sts")
caller_arn = sts.get_caller_identity()["Arn"]
print(caller_arn)
@stekern
stekern / cfn-ddb-sfn.yml
Created November 12, 2023 16:12
CloudFormation template that demonstrates how to start a Step Functions State Machine using DynamoDB Streams and EventBridge Pipes
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates a Step Functions State Machine that is executed when new items are added to a DynamoDB Table.
Resources:
Table:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
- AttributeName: "PK"
AttributeType: "S"
KeySchema:
@atheiman
atheiman / script.py
Created November 9, 2023 21:51
Convert python dictionary of many levels to single level dictionary with dot notation keys
def dict_dot_notation(d, path=[]):
d2 = {}
for k, v in d.items():
k_path = path + [str(k)]
k_formatted = ".".join(k_path)
if isinstance(v, dict):
# merge in dict with recursive call
d2 = {**d2, **dict_dot_notation(v, path=k_path)}
elif isinstance(v, list) or isinstance(v, tuple):
@phillip-le
phillip-le / assert-to-have-received-put-command-command.ts
Last active May 10, 2024 16:52
Unit Testing AWS SDK in TypeScript
it('should persist user to dynamodb', async () => {
await createUser(userInput);
expect(mockDynamoDbDocumentClient).toHaveReceivedCommandWith(PutCommand, {
TableName: 'TestUserTable',
Item: userToCreate,
});
});
@ChrisSwanson
ChrisSwanson / docker-compose.yml
Created April 4, 2023 01:24
changedetection.io playwright chrome docker compose
version: "3.8"
services:
changedetection:
container_name: changedetection
hostname: changedetection
image: ghcr.io/dgtlmoon/changedetection.io:latest
environment:
- TZ=America/Los_Angeles
- PLAYWRIGHT_DRIVER_URL=ws://playwright-chrome:3000/?stealth=1&--disable-web-security=true&token=<redacted>
@ronaldbradford
ronaldbradford / lambda.auto-shutdown.py
Created January 26, 2023 15:06
Autoshutdown AWS RDS Instances and Clusters
# this Code will help to schedule stop the RDS databasrs using Lambda
# Yesh
# Version -- 2.0
# Adapted from https://aws.amazon.com/blogs/database/schedule-amazon-rds-stop-and-start-using-aws-lambda/
import boto3
import os
import sys
import time
from datetime import datetime, timezone
@hackmajoris
hackmajoris / start-stop-rds-lambda.ts
Last active February 6, 2024 10:31
Start and Stop RDS Scheduler with Lambda and CDK TypeScript Stack
import { Handler } from 'aws-lambda';
import * as AWS from 'aws-sdk';
const rds = new AWS.RDS();
enum InstanceStatus {
STOPPED = 'stopped',
AVAILABLE = 'available',
}