Skip to content

Instantly share code, notes, and snippets.

def assumeRole(self, action):
client = self.initStsClient()
assumedRoleObject = client.assume_role(
RoleArn="arn:aws:iam::"+self.aws_accounts[self.env]["id"]+":role/"+self.aws_accounts[self.env]["role"],
RoleSessionName="Drp-" + action
)
credentials=assumedRoleObject['Credentials']
def dumpConfigToDisk(self, comp, az):
# Dump config file to disk as backup
pass
def addActionToDf(self, action):
# Add action to DataFrame
pass
def dumpDfToDisk(self):
# Dump DF to disk
if __name__ == "__main__":
c = DRP("MY_ACCOUNT")
for az in c.describeAZ():
main_logger = logging.getLogger('MAIN')
main_logger.info('Begin of the operations on az: %s', az)
waitUserInput()
c.addActionToDf("[{} / {}] Begin of the operations".format(c.env, az))
# 0) Create a new az_list without our AZ
@gmariette
gmariette / app.py
Last active October 17, 2021 18:06
#!/usr/bin/env python3
import os
from aws_cdk import core
from medium.stack import MediumLambdaStack
myenv = os.environ['MYENV']
# Init of the main application (stack)
app = core.App()
{
"app": "python3 app.py",
"context": {
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:enableStackNameDuplicates": "true",
"aws-cdk:enableDiffNoFail": "true",
"@aws-cdk/core:stackRelativeExports": "true",
"@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true,
"@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true,
"@aws-cdk/aws-kms:defaultKeyPolicies": true,
from typing_extensions import runtime
import os
from aws_cdk import (
core,
aws_lambda as _lambda,
aws_iam as iam
)
class MediumLambdaStack(core.Stack):
AWSTemplateFormatVersion: 2010-09-09
Description: Medium custom lambda stack
Resources:
CustomBackedLambda:
Type: AWS::Lambda::Function
Properties:
FunctionName: CustomBackedLambda
Runtime: python3.9
Role: my_iam_role
################################################################################
# EC2 BASTION
################################################################################
module "bastion_host_sgroup" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 4"
name = "${var.env}-${var.project}-bastion-sg"
description = "Bastion Host security group"
import os
import boto3
import psycopg2
import logging
def lambda_handler(event, context):
ssm_client = boto3.client('ssm')
logger = logging.getLogger('INIT-DB')
logger.setLevel(logging.INFO)
import logging
import os
import boto3
import json
def lambda_handler(event, context):
"""
Send a message to an Amazon SQS queue.
"""