Skip to content

Instantly share code, notes, and snippets.

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)
################################################################################
# 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"
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
from typing_extensions import runtime
import os
from aws_cdk import (
core,
aws_lambda as _lambda,
aws_iam as iam
)
class MediumLambdaStack(core.Stack):
{
"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,
@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()
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
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
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']
for i, item in enumerate(tournament_idx_lst[:-1]):
tournament_name = rows[item].find("td", class_="t-name").text.strip()
if "Pro Tennis" in tournament_name or "Futures" in tournament_name or "challenger" in tournament_name:
continue
if not tournament_dict.get(tournament_name):
tournament_dict[tournament_name] = {}
tournament_dict[tournament_name][current_date] = []
for c in range (item+1, tournament_idx_lst[i+1], 2):
tournament_dict[tournament_name][current_date].append(getPlayersFullName(rows[c].find("td", class_="t-name").a['href']) + ' vs ' + getPlayersFullName(rows[c+1].find("td", class_="t-name").a['href']))