src/kelp/__init__.py
def deploy_trail():
    """Create s3 bucket and cloudtrail via cfn"""
    my_dir = os.path.dirname(__file__)
    logger.info("Creating cloudtrail and accompanying logging bucket...")
    client = boto3.client("cloudformation", region_name="us-east-1")
    cfn_template_body = open(os.path.join(my_dir, "bucket.yml")).read()
    response = client.create_stack(
        StackName="kelp-bucket-stack",
        TemplateBody=cfn_template_body,
    )

    # Wait for bucket stack to finish deploying to deploy trail
    response = client.describe_stacks(StackName="kelp-bucket-stack")
    while response["Stacks"][0]["StackStatus"] == "CREATE_IN_PROGRESS":
        sleep(2)
        response = client.describe_stacks(StackName="kelp-bucket-stack")

    cfn_template_body = open(os.path.join(my_dir, "trail.yml")).read()
    response = client.create_stack(
        StackName="kelp-trail-stack",
        TemplateBody=cfn_template_body,
    )

    # Wait for trail to deploy to finish
    response = client.describe_stacks(StackName="kelp-trail-stack")
    while response["Stacks"][0]["StackStatus"] == "CREATE_IN_PROGRESS":
        sleep(2)
        response = client.describe_stacks(StackName="kelp-trail-stack")

    logger.info("Cloudtrail deployed successfully")
    # NOTE - Cloudtrail weird, give it a sec to settle
    sleep(3)
Create s3 bucket and cloudtrail via cfn
Create s3 bucket and cloudtrail via cfn
Create s3 bucket and cloudtrail via cfn
def deploy_trail():
    my_dir = os.path.dirname(__file__)
    logger.info("Creating cloudtrail and accompanying logging bucket...")
    client = boto3.client("cloudformation", region_name="us-east-1")
    cfn_template_body = open(os.path.join(my_dir, "bucket.yml")).read()
    response = client.create_stack(
        StackName="kelp-bucket-stack",
        TemplateBody=cfn_template_body,
    )
    response = client.describe_stacks(StackName="kelp-bucket-stack")
    while response["Stacks"][0]["StackStatus"] == "CREATE_IN_PROGRESS":
        sleep(2)
        response = client.describe_stacks(StackName="kelp-bucket-stack")
    cfn_template_body = open(os.path.join(my_dir, "trail.yml")).read()
    response = client.create_stack(
        StackName="kelp-trail-stack",
        TemplateBody=cfn_template_body,
    )
    response = client.describe_stacks(StackName="kelp-trail-stack")
    while response["Stacks"][0]["StackStatus"] == "CREATE_IN_PROGRESS":
        sleep(2)
        response = client.describe_stacks(StackName="kelp-trail-stack")
    logger.info("Cloudtrail deployed successfully")
    sleep(3)
def deploy_trail ( ) : my_dir = os . path . dirname ( __file__ ) logger . info ( "Creating cloudtrail and accompanying logging bucket..." ) client = boto3 . client ( "cloudformation" , region_name = "us-east-1" ) cfn_template_body = open ( os . path . join ( my_dir , "bucket.yml" ) ) . read ( ) response = client . create_stack ( StackName = "kelp-bucket-stack" , TemplateBody = cfn_template_body , ) response = client . describe_stacks ( StackName = "kelp-bucket-stack" ) while response [ "Stacks" ] [ 0 ] [ "StackStatus" ] == "CREATE_IN_PROGRESS" : sleep ( 2 ) response = client . describe_stacks ( StackName = "kelp-bucket-stack" ) cfn_template_body = open ( os . path . join ( my_dir , "trail.yml" ) ) . read ( ) response = client . create_stack ( StackName = "kelp-trail-stack" , TemplateBody = cfn_template_body , ) response = client . describe_stacks ( StackName = "kelp-trail-stack" ) while response [ "Stacks" ] [ 0 ] [ "StackStatus" ] == "CREATE_IN_PROGRESS" : sleep ( 2 ) response = client . describe_stacks ( StackName = "kelp-trail-stack" ) logger . info ( "Cloudtrail deployed successfully" ) sleep ( 3 )
Create s3 bucket and cloudtrail via cfn
Create s3 bucket and cloudtrail via cfn
"""Create s3 bucket and cloudtrail via cfn""" # Wait for bucket stack to finish deploying to deploy trail # Wait for trail to deploy to finish # NOTE - Cloudtrail weird, give it a sec to settle