Skip to content

Instantly share code, notes, and snippets.

@SodaDev
SodaDev / AWS login sso
Created April 17, 2020 07:16
AWS configure sso login
function aws-sso() {
aws configure sso --profile default
ACCESS_KEY_POSTFIX="\"$(aws configure list --profile default | grep access_key | awk '{print $2}' | sed 's/*//g')\""
SECRET_KEY_POSTFIX="$(aws configure list --profile default | grep secret_key | awk '{print $2}' | sed 's/*//g')"
ACCESS_KEY_FILTER=". | select(.Credentials.AccessKeyId | endswith($ACCESS_KEY_POSTFIX))"
SECRET_KEY_FILTER=". | select(.Credentials.SecretAccessKey | endswith(\"$SECRET_KEY_POSTFIX\"))"
for entry in ~/.aws/cli/cache/*
do
FOUND_ACCESS_KEY="$(cat $entry | jq -r "$ACCESS_KEY_FILTER")"
FOUND_ACCESS_SECRET="$(cat $entry | jq -r "$SECRET_KEY_FILTER")"
DROP TRIGGER IF EXISTS NEW_ROUTE;
CREATE TRIGGER NEW_ROUTE
AFTER INSERT
ON routes
FOR EACH ROW
BEGIN
CALL mysql.lambda_async(
'arn:aws:lambda:eu-west-1:XXXXXXXXXX:function:RDS-EVENTS-CONSUMER',
JSON_OBJECT('new', JSON_OBJECT(
'airportFrom', NEW.airportFrom,
DROP TRIGGER IF EXISTS DELETED_ROUTE;
CREATE TRIGGER DELETED_ROUTE
AFTER DELETE
ON routes
FOR EACH ROW
BEGIN
CALL mysql.lambda_async(
'arn:aws:lambda:eu-west-1:XXXXXXXXXX:function:RDS-EVENTS-CONSUMER',
JSON_OBJECT(
'old', JSON_OBJECT(
DROP TRIGGER IF EXISTS UPDATED_ROUTE;
CREATE TRIGGER UPDATED_ROUTE
AFTER UPDATE
ON routes
FOR EACH ROW
BEGIN
IF (
MD5(CONCAT_WS('', NEW.airportFrom, NEW.airportTo, NEW.connectingAirport, NEW.newRoute, NEW.seasonalRoute, NEW.operator, NEW.group, NEW.tags))
<> MD5(CONCAT_WS('', OLD.airportFrom, OLD.airportTo, OLD.connectingAirport, OLD.newRoute, OLD.seasonalRoute, OLD.operator, OLD.group, OLD.tags))
) THEN
START TRANSACTION;
INSERT INTO flights.routes (airportFrom, airportTo, connectingAirport, newRoute, seasonalRoute, operator, `group`, tags, similarArrivalAirportCodes, carrierCode) VALUES ('FOO', 'ROLLBACK_1', null, false, false, 'RYANAIR', 'CITY', '', '', 'FR');
INSERT INTO flights.routes (airportFrom, airportTo, connectingAirport, newRoute, seasonalRoute, operator, `group`, tags, similarArrivalAirportCodes, carrierCode) VALUES ('FOO', 'ROLLBACK_2', null, false, false, 'RYANAIR', 'CITY', '', '', 'FR');
INSERT INTO flights.routes (airportFrom, airportTo, connectingAirport, newRoute, seasonalRoute, operator, `group`, tags, similarArrivalAirportCodes, carrierCode) VALUES ('FOO', 'ROLLBACK_3', null, false, false, 'RYANAIR', 'CITY', '', '', 'FR');
ROLLBACK;
const AWS = require("aws-sdk")
const _ = require("lodash")
const dynamo = new AWS.DynamoDB.DocumentClient({
apiVersion: "2012-08-10",
region: "eu-west-1"
})
const BATCH_SIZE = 25;
const sourceTable = "<put-value-here>";
const destinationTable = "<put-value-here>";
AWSTemplateFormatVersion: 2010-09-09
Description: SSO Account Setup
Parameters:
InstanceARN:
Type: String
AllowedPattern: arn:aws:sso:::instance/(sso)?ins-[a-zA-Z0-9-.]{16}
Description: 'Enter AWS SSO InstanceARN. Ex: arn:aws:sso:::instance/ssoins-xxxxxxxxxxxxxxxx'
ConstraintDescription: AWS SSO InstanceARN - gather with aws sso-admin list-instances
IdentityStoreId:
2023-02-26T11:24:51.473000 <--- Loaded 1 messages
2023-02-26T11:24:51.473000 xxx> Test event 4
2023-02-26T11:24:51.477000 <--- Loaded 1 messages
2023-02-26T11:24:51.477000 ---> Test event 3
2023-02-26T11:24:52.819000 <--- Loaded 1 messages
2023-02-26T11:24:52.819000 ---> Test event 2
2023-02-26T11:24:52.843000 <--- Loaded 1 messages
2023-02-26T11:24:52.843000 ---> Test event 5
2023-02-26T11:24:52.877000 <--- Loaded 1 messages
2023-02-26T11:24:52.877000 ---> Test event 1
@SodaDev
SodaDev / gist:76c8a572f438248e7ca4a715034112a9
Created March 5, 2023 14:51
Batch processing without partial failures
2023-02-26T01:38:11.420000 <--- Loaded 6 messages
2023-02-26T01:38:11.420000 ---> Test event 1
2023-02-26T01:38:11.420000 ---> Test event 5
2023-02-26T01:38:11.420000 ---> Test event 9
2023-02-26T01:38:11.420000 xxx> Test event 10
2023-02-26T01:38:26.068000 <--- Loaded 4 messages
2023-02-26T01:38:26.068000 xxx> Test event 3
2023-02-26T01:38:51.377000 <--- Loaded 5 messages
@SodaDev
SodaDev / gist:5f9e448f23a828ac337aa5789093124f
Created March 5, 2023 18:23
Article SQS - Batch processing partial failures
2023-02-26T19:19:17.383000 <--- Loaded 4 messages
2023-02-26T19:19:17.383000 ---> Test event 5
2023-02-26T19:19:17.383000 ---> Test event 3
2023-02-26T19:19:17.383000 xxx> Test event 6
2023-02-26T19:19:17.383000 xxx> Test event 10
2023-02-26T19:19:28.457000 <--- Loaded 6 messages
2023-02-26T19:19:28.457000 xxx> Test event 4
2023-02-26T19:19:28.457000 xxx> Test event 2
2023-02-26T19:19:28.457000 ---> Test event 1