def _create_lambda_event_payload(self, stream_arn, records, shard_id=None): record_payloads = [] for record in records: record_payload = {} for key, val in record.items(): record_payload[first_char_to_lower(key)] = val # boto3 automatically decodes records in get_records(), so we must re-encode record_payload["data"] = to_str( base64.b64encode(record_payload["data"])) # convert datetime obj to timestamp record_payload["approximateArrivalTimestamp"] = ( record_payload["approximateArrivalTimestamp"].timestamp() * 1000) record_payloads.append({ "eventID": "{0}:{1}".format(shard_id, record_payload["sequenceNumber"]), "eventSourceARN": stream_arn, "eventSource": "aws:kinesis", "eventVersion": "1.0", "eventName": "aws:kinesis:record", "invokeIdentityArn": "arn:aws:iam::{0}:role/lambda-role".format( constants.TEST_AWS_ACCOUNT_ID), "awsRegion": aws_stack.get_region(), "kinesis": record_payload, }) return {"Records": record_payloads}
def extract_resource_attribute(resource_type, resource, attribute): LOG.debug('Extract resource attribute: %s %s' % (resource_type, attribute)) # extract resource specific attributes if resource_type == 'Lambda::Function': actual_attribute = 'FunctionArn' if attribute == 'Arn' else attribute return resource['Configuration'][actual_attribute] elif resource_type == 'DynamoDB::Table': actual_attribute = 'LatestStreamArn' if attribute == 'StreamArn' else attribute value = resource['Table'].get(actual_attribute) return value elif resource_type == 'ApiGateway::RestApi': if attribute == 'PhysicalResourceId': return resource['id'] if attribute == 'RootResourceId': resources = aws_stack.connect_to_service('apigateway').get_resources(restApiId=resource['id'])['items'] for res in resources: if res['path'] == '/' and not res.get('parentId'): return res['id'] elif resource_type == 'ApiGateway::Resource': if attribute == 'PhysicalResourceId': return resource['id'] attribute_lower = common.first_char_to_lower(attribute) return resource.get(attribute) or resource.get(attribute_lower)
def test_first_char_to_lower(self): env = common.first_char_to_lower('Foobar') self.assertEqual(env, 'foobar')
def test_first_char_to_lower(self): env = common.first_char_to_lower("Foobar") assert env == "foobar"
def test_first_char_to_lower(self): env = common.first_char_to_lower("Foobar") self.assertEqual("foobar", env)
def _get_entry(obj, key): return obj.get(key) or obj.get(first_char_to_lower(key))