Beispiel #1
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Parameter Group'''
    # Build API params
    resource_config.update(dict(DBParameterGroupName=iface.resource_id))
    # Actually create the resource
    res_id, res_arn = iface.create(resource_config)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
    def test_update_resource_arn(self):
        mock_instance = MagicMock()

        mock_instance.runtime_properties = {}

        utils.update_resource_arn(mock_instance, 'val')

        self.assertEqual(mock_instance.runtime_properties,
                         {'aws_resource_arn': 'val'})
Beispiel #3
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Instance Read Replica'''
    # Build API params
    params = ctx.instance.runtime_properties['resource_config'] or dict()
    params.update(dict(DBInstanceIdentifier=iface.resource_id))
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
Beispiel #4
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Subnet Group'''
    # Build API params
    params = ctx.instance.runtime_properties['resource_config'] or dict()
    params.update(dict(DBSubnetGroupName=iface.resource_id))
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS KMS Key"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    create_response = iface.create(params)[KEY_META]
    utils.update_resource_arn(ctx.instance, create_response.get(ARN))
    utils.update_resource_id(ctx.instance, create_response.get(KEY_ID))
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS ELB load balancer'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get('Name'),
            use_instance_id=True)
    params['Name'] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # LB attributes are only applied in modify operation.
    params.pop(LB_ATTR, {})
    # Add Subnets
    subnets_from_params = params.get(SUBNETS, [])
    subnets = \
        utils.find_rels_by_node_type(
            ctx.instance,
            SUBNET_TYPE) or utils.find_rels_by_node_name(
            ctx.instance,
            SUBNET_TYPE_DEPRECATED)
    for subnet in subnets:
        subnet_id = \
            subnet.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID]
        subnets_from_params.append(subnet_id)
    params[SUBNETS] = subnets_from_params
    # Add Security Groups
    secgroups_from_params = params.get(SECGROUPS, [])
    secgroups = \
        utils.find_rels_by_node_type(
            ctx.instance,
            SECGROUP_TYPE)
    for secgroup in secgroups:
        secgroup_id = \
            secgroup.target.instance.runtime_properties[EXTERNAL_RESOURCE_ID]
        secgroups_from_params.append(secgroup_id)
    params[SECGROUPS] = secgroups_from_params

    # Actually create the resource
    output = iface.create(params)
    lb_id = output['LoadBalancers'][0][RESOURCE_NAME]
    iface.resource_id = lb_id
    try:
        utils.update_resource_id(
            ctx.instance, lb_id)
        utils.update_resource_arn(
            ctx.instance, output['LoadBalancers'][0][LB_ARN])
    except (IndexError, KeyError) as e:
        raise NonRecoverableError(
            '{0}: {1} or {2} not located in response: {3}'.format(
                str(e), RESOURCE_NAME, LB_ARN, output))
Beispiel #7
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Lambda Permission'''
    # Build API params
    params = ctx.instance.runtime_properties['resource_config'] or dict()
    if not iface.resource_id and params.get('StatementId'):
        utils.update_resource_id(ctx.instance, params['StatementId'])
    params.update(dict(StatementId=iface.resource_id))
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
Beispiel #8
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Route53 Hosted Zone'''
    # Build API params
    params = ctx.instance.runtime_properties['resource_config'] or dict()
    params.update(dict(Name=iface.resource_id))
    if not params.get('CallerReference'):
        params.update(dict(CallerReference=str(ctx.instance.id)))
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
Beispiel #9
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Lambda Permission'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    if iface.resource_id:
        params.update({'StatementId': iface.resource_id})
    create_response = iface.create(params)
    iface.update_resource_id(create_response['StatementId'])
    utils.update_resource_id(ctx.instance, create_response['StatementId'])
    utils.update_resource_arn(ctx.instance, create_response['StatementId'])
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Subnet Group'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    if iface.resource_id:
        params.update({'DBSubnetGroupName': iface.resource_id})
    create_response = iface.create(params)
    resource_id = create_response['DBSubnetGroup']['DBSubnetGroupName']
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(
        ctx.instance, create_response['DBSubnetGroup']['DBSubnetGroupArn'])
Beispiel #11
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Lambda Function'''
    # Build API params
    params = resource_config
    params.update(dict(FunctionName=iface.resource_id))
    vpc_config = params.get('VpcConfig', dict())
    # Attach a Subnet Group if it exists
    subnet_ids = vpc_config.get('SubnetIds', list())
    for rel in utils.find_rels_by_node_type(ctx.instance,
                                            'cloudify.aws.nodes.Subnet'):
        subnet_ids.append(
            utils.get_resource_id(node=rel.target.node,
                                  instance=rel.target.instance,
                                  raise_on_missing=True))
    vpc_config['SubnetIds'] = subnet_ids
    # Attach any security groups if they exist
    security_groups = vpc_config.get('SecurityGroupIds', list())
    for rel in utils.find_rels_by_node_type(
            ctx.instance, 'cloudify.aws.nodes.SecurityGroup'):
        security_groups.append(
            utils.get_resource_id(node=rel.target.node,
                                  instance=rel.target.instance,
                                  raise_on_missing=True))
    vpc_config['SecurityGroupIds'] = security_groups
    params['VpcConfig'] = vpc_config
    # Attach an IAM Role if it exists
    iam_role = utils.find_rel_by_node_type(ctx.instance,
                                           'cloudify.nodes.aws.iam.Role')
    if iam_role:
        params['Role'] = utils.get_resource_arn(
            node=iam_role.target.node,
            instance=iam_role.target.instance,
            raise_on_missing=True)
    # Handle user-profided code ZIP file
    if params.get('Code', dict()).get('ZipFile'):
        codezip = params['Code']['ZipFile']
        ctx.logger.debug('ZipFile: "%s" (%s)' % (codezip, type(codezip)))
        if not path_exists(codezip):
            codezip = ctx.download_resource(codezip)
            ctx.logger.debug('Downloaded resource: "%s"' % codezip)
            with open(codezip, mode='rb') as _file:
                params['Code']['ZipFile'] = _file.read()
            ctx.logger.debug('Deleting resource: "%s"' % codezip)
            os_remove(codezip)
        else:
            with open(codezip, mode='rb') as _file:
                params['Code']['ZipFile'] = _file.read()
    # Actually create the resource
    create_response = iface.create(params)
    resource_id = create_response['FunctionName']
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(ctx.instance, create_response['FunctionArn'])
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Route53 Hosted Zone'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    if iface.resource_id:
        params.update({'Name': iface.resource_id})
    if not params.get('CallerReference'):
        params.update(dict(CallerReference=str(ctx.instance.id)))
    # Actually create the resource
    create_response = iface.create(params)['HostedZone']['Id']
    iface.update_resource_id(create_response)
    utils.update_resource_id(ctx.instance, create_response)
    utils.update_resource_arn(ctx.instance, create_response)
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Instance Read Replica'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    if iface.resource_id:
        params.update({'DBInstanceIdentifier': iface.resource_id})
    # Actually create the resource
    create_response = iface.create(params)
    resource_id = create_response['DBInstance']['DBInstanceIdentifier']
    iface.update_resource_id(resource_id)
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(
        ctx.instance, create_response['DBInstance']['DBInstanceArn'])
Beispiel #14
0
def start(ctx, iface, resource_config, **_):
    '''Updates an AWS RDS Instance Runtime Properties'''

    db_instance = iface.properties
    for key, value in db_instance.items():
        if key == 'DBInstanceIdentifier':
            iface.update_resource_id(value)
            utils.update_resource_id(ctx.instance, value)
            continue
        elif key == 'DBInstanceArn':
            utils.update_resource_arn(ctx.instance, value)
            continue
        elif isinstance(value, datetime):
            value = str(value)
        ctx.instance.runtime_properties[key] = value
Beispiel #15
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Cloudwatch Events Rule"""
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)
    # Actually create the resource
    rule_arn = iface.create(params)
    utils.update_resource_arn(ctx.instance, rule_arn)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS SNS Subscription"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()

    topic_arn = params.get(TOPIC_ARN)
    # Add the required TopicArn parameter.
    if not topic_arn:
        rel = \
            utils.find_rel_by_node_type(
                ctx.instance,
                TOPIC_TYPE)
        topic_arn = \
            rel.target.instance.runtime_properties.get(
                EXTERNAL_RESOURCE_ARN)
        ctx.instance.runtime_properties[TOPIC_ARN] = \
            topic_arn
        params[TOPIC_ARN] = topic_arn

    topic_iface = SNSTopic(ctx_node=ctx.node,
                           resource_id=topic_arn,
                           client=iface.client,
                           logger=ctx.logger)

    # Subscribe Endpoint is the arn of an endpoint
    endpoint_name = params.get('Endpoint')
    if not endpoint_name:
        raise NonRecoverableError(
            'Endpoint ARN or node_name was not provided.')

    # If endpoint_name is not a valid arn get arn from relationship.
    if not utils.validate_arn(endpoint_name):
        rel = \
            utils.find_rels_by_node_name(
                ctx.instance,
                endpoint_name)[0]
        endpoint_arn = \
            rel.target.instance.runtime_properties.get(
                EXTERNAL_RESOURCE_ARN)
        params['Endpoint'] = endpoint_arn

    # Request the subscription
    request_arn = topic_iface.subscribe(params)
    utils.update_resource_id(ctx.instance, request_arn)
    utils.update_resource_arn(ctx.instance, request_arn)
Beispiel #17
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS ECS Service"""

    params = dict() if not resource_config else resource_config.copy()
    # Get the cluster name from either params or a relationship.
    cluster_name = params.get(CLUSTER)
    if not cluster_name:
        params[CLUSTER] = get_cluster_name(ctx)

    ctx.instance.runtime_properties[SERVICE] = params.get(SERVICE_RESOURCE)
    utils.update_resource_id(ctx.instance, params.get(SERVICE_RESOURCE))

    iface = prepare_describe_service_filter(resource_config.copy(), iface)
    response = iface.create(params)
    if response and response.get(SERVICE):
        resource_arn = response[SERVICE].get(SERVICE_ARN)
        utils.update_resource_arn(ctx.instance, resource_arn)
Beispiel #18
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS ECS Cluster"""
    params = dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(CLUSTER_RESOURCE_NAME),
            use_instance_id=True
        )

    utils.update_resource_id(ctx.instance, resource_id)
    iface = prepare_describe_cluster_filter(resource_config.copy(), iface)
    response = iface.create(params)
    if response and response.get(CLUSTER):
        resource_arn = response[CLUSTER].get(CLUSTER_ARN)
        utils.update_resource_arn(ctx.instance, resource_arn)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS ECS Task Definition"""
    params = dict() if not resource_config else resource_config.copy()
    # Get the cluster name from either params or a relationship.
    task_definition_name = params.get(TASK_DEFINITION_FAMILY)

    ctx.instance.runtime_properties[
        TASK_DEFINITION_RESOURCE] = task_definition_name

    utils.update_resource_id(ctx.instance, task_definition_name)
    iface = prepare_describe_task_definition_filter(
        resource_config.copy(), iface
    )
    response = iface.create(params)
    if response and response.get(TASK_DEFINITION):
        resource_arn = response[TASK_DEFINITION].get(TASK_DEFINITION_ARN)
        utils.update_resource_arn(ctx.instance, resource_arn)
Beispiel #20
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Group'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
def create(ctx, iface, resource_config, **_):
    """Creates an AWS SNS Topic"""
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        )
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Actually create the resource
    res_id = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_id)
Beispiel #22
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS Autoscaling Autoscaling Launch Configuration"""
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Add Security Groups
    secgroups_list = params.get(SECGROUPS, [])
    params[SECGROUPS] = \
        utils.add_resources_from_rels(
            ctx.instance,
            SECGROUP_TYPE,
            secgroups_list)

    image_id = params.get(IMAGEID)

    # Add Instance and Instance Type
    instance_id = params.get(INSTANCEID)
    instance_type = params.get(INSTANCE_TYPE_PROPERTY)
    if not image_id and not instance_id:
        instance_id = utils.find_resource_id_by_type(ctx.instance,
                                                     INSTANCE_TYPE)
        params.update({INSTANCEID: instance_id})
    if instance_id and not instance_type:
        targ = utils.find_rel_by_node_type(ctx.instance, INSTANCE_TYPE)
        if targ:
            instance_type = \
                targ.target.node.properties.get(
                    INSTANCE_TYPE_PROPERTY_DEPRECATED)
        params.update({INSTANCE_TYPE_PROPERTY: instance_type})

    utils.update_resource_id(ctx.instance, params.get(RESOURCE_NAME))
    iface.update_resource_id(params.get(RESOURCE_NAME))
    # Actually create the resource
    resource_arn = iface.create(params)
    utils.update_resource_arn(ctx.instance, resource_arn)
Beispiel #23
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS RDS Instance'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    params.update(dict(DBInstanceIdentifier=iface.resource_id))
    # Actually create the resource
    res = iface.create(params)
    db_instance = res['DBInstance']
    for key, value in db_instance.items():
        if key == 'DBInstanceIdentifier':
            iface.update_resource_id(value)
            utils.update_resource_id(ctx.instance, value)
            continue
        elif key == 'DBInstanceArn':
            utils.update_resource_arn(ctx.instance, value)
            continue
        elif isinstance(value, datetime):
            value = str(value)
        ctx.instance.runtime_properties[key] = value
Beispiel #24
0
def create(ctx, iface, resource_config, **_):
    """Creates an AWS DynamoDB Table"""

    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
Beispiel #25
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Role'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        ) or iface.resource_id
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    if 'AssumeRolePolicyDocument' in params and \
            isinstance(params['AssumeRolePolicyDocument'], dict):
        params['AssumeRolePolicyDocument'] = \
            json_dumps(params['AssumeRolePolicyDocument'])
    # Actually create the resource
    create_response = iface.create(params)
    resource_id = create_response['Role']['RoleName']
    iface.update_resource_id(resource_id)
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(ctx.instance, create_response['Role']['Arn'])

    # attach policy role
    policies_arn = []
    policies = _.get('modify_role_attribute_args', [])
    for policy in policies:
        payload = dict()
        payload['RoleName'] = resource_id
        payload['PolicyArn'] = policy['PolicyArn']
        policies_arn.append(payload['PolicyArn'])
        iface.attach_policy(payload)

    # If there are policies added attached to role, then we need to make
    # sure that when uninstall triggers, all the attached policies arn are
    # available to detach
    if policies_arn:
        ctx.instance.runtime_properties['policies'] = policies_arn
Beispiel #26
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM User'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        iface.resource_id or \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True)
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    # Actually create the resource
    create_response = iface.create(params)
    resource_id = create_response['User']['UserName']
    iface.update_resource_id(resource_id)
    utils.update_resource_id(ctx.instance, resource_id)
    utils.update_resource_arn(ctx.instance, create_response['User']['Arn'])
Beispiel #27
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS IAM Policy'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        ) or iface.resource_id
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    if 'PolicyDocument' in params and \
            isinstance(params['PolicyDocument'], dict):
        params['PolicyDocument'] = json_dumps(params['PolicyDocument'])
    # Actually create the resource
    res_id, res_arn = iface.create(params)
    utils.update_resource_id(ctx.instance, res_id)
    utils.update_resource_arn(ctx.instance, res_arn)
Beispiel #28
0
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS Lambda Permission'''
    # Build API params
    params = \
        dict() if not resource_config else resource_config.copy()
    if iface.resource_id:
        params.update({'StatementId': iface.resource_id})
    create_response = iface.create(params)

    statement = create_response.get('Statement')
    # The actual value for key "statement" is not a python dict type,
    # so it is required to check if it is "unicode" and then convert it back
    # as python dict type

    if statement:
        if isinstance(statement, unicode):
            statement = json.loads(statement)

        resource_id = statement['Sid'] if statement.get('Sid') else None
        iface.update_resource_id(resource_id)
        utils.update_resource_id(ctx.instance, resource_id)
        utils.update_resource_arn(ctx.instance, resource_id)
def create(ctx, iface, resource_config, **_):
    '''Creates an AWS ELB rule'''
    # Build API params
    params = \
        ctx.instance.runtime_properties['resource_config'] or resource_config

    if LISTENER_ARN not in params:
        targs = \
            utils.find_rels_by_node_type(
                ctx.instance,
                LISTENER_TYPE)
        listener_arn = \
            targs[0].target.instance.runtime_properties[EXTERNAL_RESOURCE_ARN]
        params.update({LISTENER_ARN: listener_arn})
        del targs

    for action in params.get('Actions', []):
        target_grp = action.get(TARGET_ARN)
        if not ARN_MATCHER.match(action.get(target_grp, '')):
            targs = \
                utils.find_rels_by_node_type(
                    ctx.instance,
                    TARGET_TYPE)
            for targ in targs:
                target_group_arn = \
                    targ.target.instance.runtime_properties[
                        EXTERNAL_RESOURCE_ARN]
                if targ.target.node.name == target_grp:
                    action.update({TARGET_ARN: target_group_arn})

    # Actually create the resource
    create_response = iface.create(params)
    iface.update_resource_id(create_response['Rules'][0][RULE_ARN])
    utils.update_resource_id(ctx.instance,
                             create_response['Rules'][0][RULE_ARN])
    utils.update_resource_arn(ctx.instance,
                              create_response['Rules'][0][RULE_ARN])
def create(ctx, iface, resource_config, **_):
    """Creates an AWS SQS Queue"""
    # Create a copy of the resource config for clean manipulation.
    params = \
        dict() if not resource_config else resource_config.copy()
    resource_id = \
        utils.get_resource_id(
            ctx.node,
            ctx.instance,
            params.get(RESOURCE_NAME),
            use_instance_id=True
        )
    params[RESOURCE_NAME] = resource_id
    utils.update_resource_id(ctx.instance, resource_id)

    queue_attributes = params.get('Attributes', {})
    queue_attributes_policy = queue_attributes.get('Policy')
    if not isinstance(queue_attributes_policy, basestring):
        queue_attributes[POLICY] = json.dumps(queue_attributes_policy)

    # Actually create the resource
    create_response = iface.create(params)
    # Attempt to retrieve the ARN.
    try:
        resource_attributes = iface.client.get_queue_attributes(
            QueueUrl=create_response[QUEUE_URL],
            AttributeNames=[QUEUE_ARN])
    except ClientError:
        utils.update_resource_arn(
            ctx.instance,
            None)
    else:
        utils.update_resource_arn(
            ctx.instance,
            resource_attributes.get('Attributes', {}).get(QUEUE_ARN))
    utils.update_resource_id(ctx.instance, create_response[QUEUE_URL])