for generator in [
                    api_gateway_redictor_api_resource,
                    domain_name_redirector_api_resource,
                    base_path_mapping_redirector_api_resource
            ]:
                (resource_name,
                 resource_val) = generator(name, redirector_properties)
                new_resources[resource_name] = resource_val
        else:
            new_resources[name] = val
    fragment['Resources'] = new_resources


REDIRECTOR_PROPERTIES_SCHEMA = tolerant_schema({
    'CertificateArn': object,
    'DomainName': object,
    'Location': object,
})

STAGE_NAME = 'redirector'


def validate_properties(properties):
    return box(properties, schema=REDIRECTOR_PROPERTIES_SCHEMA)


def api_gateway_redictor_api_resource(redirector_name, properties):
    name = api_name(redirector_name)
    resource = {
        'Type': 'AWS::Serverless::Api',
        'Properties': {
Example #2
0
import logging

import boto3
from box import Box
from crhelper import CfnResource

from codesmith.common.cfn import resource_properties, physical_resource_id
from codesmith.common.schema import non_empty_string, tolerant_schema

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

rds = boto3.client('rds')

properties_schema = tolerant_schema({'DbInstanceIdentifier': non_empty_string})


def validate_properties(properties):
    return Box(properties_schema.validate(properties), camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
    db_instances = rds.describe_db_instances(
        DBInstanceIdentifier=properties.db_instance_identifier)
    return db_instances['DBInstances'][0]['DbiResourceId']

import codesmith.common.cfn as cfn
from codesmith.common.cfn import resource_properties, old_resource_properties
from codesmith.common.common import extract_region
from codesmith.common.schema import box, encoded_bool, non_empty_string, tolerant_schema

log = structlog.get_logger()
helper = CfnResource()
r53 = boto3.client('route53')

#
# Property validation
#

properties_schema = tolerant_schema({
    'CertificateArn': non_empty_string,
    Optional('HostedZoneName'): non_empty_string,
    Optional('HostedZoneId'): non_empty_string,
    Optional('WithCaaRecords', default=True): encoded_bool
})


def validate_properties(properties):
    p = box(properties, schema=properties_schema)
    hosted_zone_name = p.get('HostedZoneName')
    hosted_zone_id = p.get('HostedZoneId')
    if (not hosted_zone_name) and (not hosted_zone_id):
        raise ValueError('one of HostedZoneName or HostedZoneId must be defined')
    if hosted_zone_name and hosted_zone_id:
        raise ValueError('only of HostedZoneName or HostedZoneId may be defined')
    p = complete_hosted_zone_data(p)
    return p
Example #4
0
import boto3
from box import Box
from crhelper import CfnResource

import codesmith.common.cfn as cfn
from codesmith.common.cfn import logical_resource_id, resource_properties
from codesmith.common.schema import non_empty_string, tolerant_schema

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

ecr = boto3.client('ecr')
cf = boto3.client('cloudformation')

properties_schema = tolerant_schema({'Repository': non_empty_string})


def validate_properties(properties):
    return Box(properties_schema.validate(properties), camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
    return physical_resource_id(event, properties)


def physical_resource_id(event, properties):
    return '{0}:{1}'.format(logical_resource_id(event), properties.repository)
from box import Box
from crhelper import CfnResource

from codesmith.common import naming, cfn
from codesmith.common.calc import calculator, SSM_PARAMETER_DESCRIPTION
from codesmith.common.cfn import resource_properties, logical_resource_id
from codesmith.common.schema import non_empty_string, tolerant_schema
from codesmith.common.ssm import put_string_parameter, fetch_string_parameter

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

ssm = boto3.client('ssm')

properties_schema = tolerant_schema({'Sequence': non_empty_string})


def validate_properties(properties):
    return Box(properties_schema.validate(properties), camel_killer_box=True)


@helper.create
@helper.delete
def create(event, _):
    properties = validate_properties(resource_properties(event))
    physical_id = physical_resource_id(event, properties)

    value = next_value(properties)

    helper.Data.update({'ValueText': str(value), 'Value': value})
Example #6
0
ssm = boto3.client('ssm')
step = boto3.client('stepfunctions')

#
# 1. Property validation
#

properties_schema = tolerant_schema({
    'DomainName':
    non_empty_string,
    Optional('Region'):
    non_empty_string,
    Optional('SubjectAlternativeNames', default=[]): [str],
    Optional('Tags', default=[]): {
        'Key': non_empty_string,
        'Value': non_empty_string
    },
    Optional('HostedZoneName'):
    non_empty_string,
    Optional('HostedZoneId'):
    non_empty_string,
    Optional('WithCaaRecords', default=True):
    encoded_bool
})


def validate_properties(properties):
    p = box(properties, schema=properties_schema)
    hosted_zone_name = p.get('HostedZoneName')
    hosted_zone_id = p.get('HostedZoneId')
    if (not hosted_zone_name) and (not hosted_zone_id):
from crhelper import CfnResource
from schema import Optional

import codesmith.common.naming as naming
from codesmith.common.cfn import resource_properties
from codesmith.common.schema import encoded_bool, non_empty_string, tolerant_schema
from codesmith.common.ssm import put_string_parameter, silent_delete_parameter_from_event

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

properties_schema = tolerant_schema({
    'UserPoolId': non_empty_string,
    'UserPoolClientId': non_empty_string,
    Optional('All', default=False): encoded_bool,
    Optional('Domains', default=[]): [str],
    Optional('Emails', default=[]): [str]
})

ssm = boto3.client('ssm')


def validate_properties(props):
    return Box(properties_schema.validate(props), camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    p = validate_properties(resource_properties(event))
Example #8
0
from crhelper import CfnResource

import codesmith.common.cfn as cfn
from codesmith.common.cfn import logical_resource_id, resource_properties
from codesmith.common.schema import box, non_empty_string, tolerant_schema

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

elb = boto3.client('elbv2')
cf = boto3.client('cloudformation')

properties_schema = tolerant_schema({
    'ListenerArn': non_empty_string,
    'Rule1Arn': non_empty_string,
    'Rule2Arn': non_empty_string,
    'Trigger': non_empty_string
})


def validate_properties(properties):
    return box(properties, schema=properties_schema)


@helper.create
def create(event, _):
    properties = validate_properties(resource_properties(event))
    return physical_resource_id(event, properties)


def physical_resource_id(event, properties):
import boto3
import structlog

import codesmith.common.cfn as cfn
from codesmith.common.schema import box, non_empty_string, tolerant_schema

MAX_ROUND_COUNT = 60

log = structlog.get_logger()

#
# Property validation
#

properties_schema = tolerant_schema({'CertificateArn': non_empty_string})


def validate_properties(properties):
    p = box(properties, schema=properties_schema)
    return p


def handler(event, _):
    log.msg('', sf_event=event)
    round_f = event.get("Round")
    round_index = int(round_f) if round_f else 0
    check = check_certificate(event, round_index)
    event["IsDone"] = check
    event["Round"] = round_index + 1
    return event
Example #10
0
from codesmith.common import naming
from codesmith.common.calc import calculator, SSM_PARAMETER_DESCRIPTION
from codesmith.common.cfn import resource_properties
from codesmith.common.schema import non_empty_string, tolerant_schema
from codesmith.common.ssm import silent_delete_parameter_from_event, put_string_parameter

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

ssm = boto3.client('ssm')
expression_parser = calculator(1)

properties_schema = tolerant_schema({
    'SequenceName': non_empty_string,
    Optional('Expression'): non_empty_string
})


def validate_properties(properties):
    p = properties_schema.validate(properties)
    if 'expression' not in p:
        p['expression'] = 'x'
    expression_parser.parse(p['expression'])
    return Box(p, camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
Example #11
0
from schema import Optional

import codesmith.common.cfn as cfn
from codesmith.common.cfn import logical_resource_id, resource_properties
from codesmith.common.schema import non_empty_string, tolerant_schema

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

s3 = boto3.client('s3')
cf = boto3.client('cloudformation')

properties_schema = tolerant_schema({
    'Bucket': non_empty_string,

    Optional('Prefix', default=''): str,
})


def validate_properties(properties):
    return Box(properties_schema.validate(properties), camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
    return physical_resource_id(event, properties)

from codesmith.common.schema import box, non_empty_string, tolerant_schema, encoded_int

log = structlog.get_logger()
helper = CfnResource()
cf = boto3.client('cloudformation')
s3 = boto3.client('s3')
ssm = boto3.client('ssm')

#
# Property validation
#

properties_schema = tolerant_schema({
    'Bucket':
    non_empty_string,
    'CurrentReleasePrefix':
    non_empty_string,
    Optional('ReleaseCountNumber', default=10):
    encoded_int
})


def validate_properties(properties):
    return box(properties, schema=properties_schema)


@helper.create
def create(event, _):
    properties = validate_properties(resource_properties(event))
    parameter_name = naming.s3_release_cleanup_parameter_name(
        stack_arn=cfn.stack_id(event),
        logical_resource_id=cfn.logical_resource_id(event))
from crhelper import CfnResource
from schema import Optional

from codesmith.common.cfn import resource_properties, physical_resource_id
from codesmith.common.schema import non_empty_string, tolerant_schema

helper = CfnResource()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

idp = boto3.client('cognito-idp')

properties_schema = tolerant_schema({
    'UserPoolId': non_empty_string,
    'Domain': non_empty_string,
    Optional('CustomDomainConfig', {}): {
        'CertificateArn': non_empty_string
    }
})


def validate_properties(properties):
    return Box(properties_schema.validate(properties), camel_killer_box=True)


@helper.create
@helper.update
def create(event, _):
    properties = validate_properties(resource_properties(event))
    certificate_arn = properties.custom_domain_config.certificate_arn
    if certificate_arn is None: