Skip to content

Instantly share code, notes, and snippets.

cat test.json | gzip | openssl base64 -A > test.out
# pacakaging and deploying sam function
sam build --use-container -m ./requirements.txt
sam package --s3-bucket DEPLOYMENT-BUCKET --output-template-file packaged.yaml --region eu-west-1
sam deploy --template-file ./packaged.yaml --stack-name CLOUDFORMATION-STACK-NAME --capabilities CAPABILITY_IAM --region eu-west-1
aws kms encrypt --key-id #### --plaintext "onetwothree 123" --query CiphertextBlob --output text | base64 --decode > out.blob
aws kms decrypt --key-id #### --ciphertext-blob fileb://out.blob --query Plaintext --output text | base64 --decode
# cloudformation package and deploy
aws cloudformation package --s3-bucket BUCKET-NAME --output-template-file packaged.yaml --region eu-west-1 --template-file template.yaml
aws cloudformation deploy --template-file packaged.yaml --stack-name STACK-NAME --parameter-overrides ParameterName=ParameterValue --capabilities CAPABILITY_IAM
#!/bin/bash
#
set -e
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_SECURITY_TOKEN
ROLEARN="${1}"
SESSIONNAME="sumething"
KST=$(aws2 sts assume-role --role-arn $ROLEARN \
--role-session-name $SESSIONNAME)
aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`tag_key`].Value, `tag_value`)].[AutoScalingGroupName]'
# If the tag value is true it must be escaped with "
aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`tag_key`].Value, `"true"`)].[AutoScalingGroupName]'
@markymarkus
markymarkus / gist:9defa002e8ac27992c83ca7d93d313cb
Created February 9, 2021 10:58
sh script to assume-role from Gitlab
#!/bin/sh
echo "Assuming role based on CI job name $CI_JOB_NAME"
case "$CI_JOB_NAME" in
*"prod")
AWS_DEPLOYMENT_ROLE=$AWS_DEPLOYMENT_ROLE_PROD
AWS_EXTERNALID=$AWS_EXTERNALID_PROD
;;
*"test")
#!/bin/bash
TO="USER@XXXX.XXX"
FROM="SENDER@XXXX.XXX"
SUBJECT="Test mail"
MESSAGE="liam tseT"
date="$(date +"%a, %d %b %Y %H:%M:%S %Z")"
priv_key="AWS_SECRET_KEY"
access_key="AWS_ACCESS_KEY"
# usage json_to_firehose.py input_file.json my_firehose_stream
import json
import sys
import boto3
client = boto3.client('firehose')
filename = sys.argv[1]
streamname = sys.argv[2]
LogsRule:
Type: AWS::Events::Rule
Properties:
EventBusName: 'default'
EventPattern:
source:
- aws.ssm
detail-type:
- "EC2 State Manager Association State Change"
State: ENABLED