Ejemplo n.º 1
0
def add_default_resource_props(resource_props, stack_name, resource_name=None):
    """ Apply some fixes to resource props which otherwise cause deployments to fail """

    res_type = resource_props['Type']
    props = resource_props.get('Properties', {})

    if res_type == 'AWS::Lambda::EventSourceMapping' and not props.get('StartingPosition'):
        props['StartingPosition'] = 'LATEST'

    if res_type == 'AWS::SNS::Topic' and not props.get('TopicName'):
        props['TopicName'] = 'topic-%s' % short_uid()

    if res_type == 'AWS::SQS::Queue' and not props.get('QueueName'):
        props['QueueName'] = 'queue-%s' % short_uid()

    if res_type == 'AWS::ApiGateway::RestApi':
        props['Name'] = props.get('Name') or resource_name

    if res_type == 'AWS::DynamoDB::Table':
        update_dynamodb_index_resource(resource_props)

    # generate default names for certain resource types
    default_attrs = (('AWS::IAM::Role', 'RoleName'), ('AWS::Events::Rule', 'Name'))
    for entry in default_attrs:
        if res_type == entry[0] and not props.get(entry[1]):
            props[entry[1]] = 'cf-%s-%s' % (stack_name, md5(canonical_json(props)))
Ejemplo n.º 2
0
 def add_default_props(resource_props):
     # apply some fixes which otherwise cause deployments to fail
     res_type = resource_props['Type']
     props = resource_props.get('Properties', {})
     if res_type == 'AWS::Lambda::EventSourceMapping' and not props.get(
             'StartingPosition'):
         props['StartingPosition'] = 'LATEST'
     if res_type == 'AWS::IAM::Role' and not props.get('RoleName'):
         props['RoleName'] = 'cf-%s-%s' % (stack_name,
                                           md5(canonical_json(props)))
Ejemplo n.º 3
0
 def add_default_props(resource_props):
     """ apply some fixes which otherwise cause deployments to fail """
     res_type = resource_props['Type']
     props = resource_props.get('Properties', {})
     if res_type == 'AWS::Lambda::EventSourceMapping' and not props.get('StartingPosition'):
         props['StartingPosition'] = 'LATEST'
     # generate default names for certain resource types
     default_attrs = (('AWS::IAM::Role', 'RoleName'), ('AWS::Events::Rule', 'Name'))
     for entry in default_attrs:
         if res_type == entry[0] and not props.get(entry[1]):
             props[entry[1]] = 'cf-%s-%s' % (stack_name, md5(canonical_json(props)))
Ejemplo n.º 4
0
 def get_physical_resource_id(self, attribute=None, **kwargs):
     policy = self.props.get("Policy")
     return policy and md5(canonical_json(json.loads(policy)))