This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import boto3 | |
import os | |
from botocore.exceptions import ClientError | |
KEY_ID = 'aws_access_key_id' | |
SECRET_KEY = 'aws_secret_access_key' | |
SESSION_TOKEN = 'aws_session_token' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import os | |
import boto3 | |
import shlex | |
def rotate(profile: str): | |
sts = boto3.client('sts') | |
iam = boto3.client('iam') | |
user_arn = sts.get_caller_identity()['Arn'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eox pipefail | |
if [ "$1" == "" ]; then | |
echo "usage: assume-role arn [session-name=nikolatosic\$(date +%s)] [duration=900]" | |
exit 1 | |
fi | |
if [ "$2" == "" ]; then | |
echo "usage: assume-role arn [session-name\$(date +%s)] [duration=900]" | |
session_name="nikolatosic$(date +%s)" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
from urllib.request import urlopen, Request, HTTPError, URLError | |
import json | |
logger = logging.getLogger() | |
class CustomResourceResponse: | |
def __init__(self, event): | |
self.event = event | |
self.response = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def handler(event, payload): | |
print(json.dumps(event)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Parameters: | |
DeployCustomResource: | |
Type: String | |
Default: false | |
AllowedValues: [true, false] | |
Conditions: | |
DeployCustomResource: !Equals [ !Ref DeployCustomResource, 'true' ] | |
Resources: | |
# .. other definitions including backing lambda | |
MyCustomResource: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
physical_id = get_physical_id(event) | |
if request_type == 'Create' or request_type == 'Update: | |
if resource_exists(physical_id): | |
print(f'{physical_id} will be overwritten') | |
create_resource() | |
response.success(physical_id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_physical_id(r_properties): | |
""" Generated resource id """ | |
bucket = r_properties['Bucket'] | |
key = r_properties['Key'] | |
return f's3://{bucket}/{key}' | |
def cr_handler(event, context): | |
""" | |
Create, Update or Remove S3 object | |
as Custom Resource for AWS CloudFormation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import json | |
def handler(payload, context): | |
try: | |
response = CustomResourceResponse(payload) | |
# follow rule 2 - alway log the paylod | |
logging.info(json.dumps(payload)) | |
## TODO: handle request from CFN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isolate_binary() { | |
binary=$(which $1) | |
libs=$(ldd -v $binary | grep -o '/.*[[:space:]]') | |
libs=($libs) | |
mkdir -p ${2}$(dirname $binary) | |
cp -vn ${binary} ${2}${binary} | |
for l in "${libs[@]}"; do mkdir -p ${2}$(dirname $l) && cp -vn ${l} ${2}${l}; done | |
} |
NewerOlder