Beispiel #1
0
def create_environment(
            region,
            app_id,
            environment_name,
            version_label,
            solution_stack_name,
            option_settings,
            is_worker_tier = False
            ):
    if is_worker_tier:
        tier_dict = worker_tier_dict
    else:
        tier_dict = webhead_tier_dict
    eb = boto3.client('elasticbeanstalk', region)
    try_client(
        lambda: eb.create_environment(
            ApplicationName = app_id,
            EnvironmentName = environment_name,
            SolutionStackName = solution_stack_name,
            VersionLabel = version_label,
            OptionSettings = option_settings,
            Tier = tier_dict,
            Tags = [{'Key': 'bosscat', 'Value': environment_name}]
            )
        )
Beispiel #2
0
def ensure_bucket(bucket_name, region, bucket_policy=None, cors_dict=None):
    client = get_s3_client()
    if region == 'us-east-1':
        region = None
    try:
        if region:
            bucket = client.create_bucket(
                Bucket = bucket_name,
                CreateBucketConfiguration = {
                    'LocationConstraint': region
                    }
                )
        else:
            bucket = client.create_bucket(Bucket=bucket_name)
    except ClientError as ex:
        if client_error_code(ex) != BUCKET_ALREADY_OWNED_BY_YOU:
            raise
    if cors_dict:
        client.put_bucket_cors(Bucket=bucket_name, CORSConfiguration=cors_dict)
    if bucket_policy:
        try_client(
            lambda: client.put_bucket_policy(
                Bucket=bucket_name,
                Policy=bucket_policy
                )
            )
Beispiel #3
0
def ensure_queue(queue_name, region, queue_policy=None, redrive_policy=None):
    client = boto3.client('sqs', region)
    attributes = {}
    if queue_policy:
        attributes['Policy'] = json.dumps(queue_policy)
    if redrive_policy:
        attributes['RedrivePolicy'] = json.dumps(redrive_policy)
    try_client(
        lambda: client.create_queue(
            QueueName = queue_name,
            Attributes = attributes
            )
        )
Beispiel #4
0
def ensure_instance_profile(instance_profile_name, role_name):
    client = boto3.client('iam')
    created = utils.try_client(
        lambda: client.create_instance_profile(
            InstanceProfileName = instance_profile_name
            ),
        ignore = [ENTITY_ALREADY_EXISTS]
        )
    if created:
        utils.try_client(
            lambda: client.add_role_to_instance_profile(
                InstanceProfileName = instance_profile_name,
                RoleName = role_name
                )
            )
Beispiel #5
0
def create_application_version(
            region,
            app_id,
            source_bucket_name,
            bundle_name,
            bundle_description
            ):
    eb = boto3.client('elasticbeanstalk', region)
    try_client(
        lambda: eb.create_application_version(
            ApplicationName = app_id,
            VersionLabel = bundle_name,
            Description = bundle_description,
            SourceBundle = {
                'S3Bucket': source_bucket_name,
                'S3Key': '{}/{}.zip'.format(app_id, bundle_name)
                }
            )
        )
Beispiel #6
0
def ensure_role(
            role_name,
            policy_name,
            policy_document,
            assume_role_policy_document = DEFAULT_ASSUME_ROLE_POLICY_DOCUMENT
            ):
    client = boto3.client('iam')
    utils.try_client(
        lambda: client.create_role(
            RoleName = role_name,
            AssumeRolePolicyDocument = json.dumps(assume_role_policy_document)
            ),
        ignore = [ENTITY_ALREADY_EXISTS]
        )
    utils.try_client(
        lambda: client.put_role_policy(
            RoleName = role_name,
            PolicyName = policy_name,
            PolicyDocument = json.dumps(policy_document)
            )
        )
Beispiel #7
0
def upload_local_file_to_bucket(local_filename, bucket_name, key):
    client = get_s3_client()
    try_client(
        lambda: client.upload_file(local_filename, bucket_name, key)
        )