No body needed here as POST is a request for a pre-signed upload URL. Create an entry for it in dynamo and return upload URL
(event, context)
| 5 | |
| 6 | |
| 7 | def create(event, context): |
| 8 | """ |
| 9 | No body needed here as POST is a request for a pre-signed upload URL. |
| 10 | Create an entry for it in dynamo and return upload URL |
| 11 | """ |
| 12 | # Sample events using different lambda integrations: |
| 13 | # |
| 14 | # _lambda_proxy_event = {'resource': '/asset', 'path': '/asset', 'httpMethod': 'POST', |
| 15 | # 'headers': {'Accept': '*/*', 'CloudFront-Forwarded-Proto': 'https', |
| 16 | # 'CloudFront-Is-Desktop-Viewer': 'true', 'CloudFront-Is-Mobile-Viewer': 'false', |
| 17 | # 'CloudFront-Is-SmartTV-Viewer': 'false', 'CloudFront-Is-Tablet-Viewer': 'false', |
| 18 | # 'CloudFront-Viewer-Country': 'US', |
| 19 | # 'Host': 'c1xblyjsid.execute-api.us-east-1.amazonaws.com', |
| 20 | # 'User-Agent': 'curl/7.56.1', |
| 21 | # 'Via': '1.1 5c75b37c7e0aa5868b6499a5c4448d1f.cloudfront.net (CloudFront)', |
| 22 | # 'X-Amz-Cf-Id': 'XG5WkkaGYGdbA9KAm7Hsbl5t7D7KmALE4Q2LdOwbXYoCFJZxyyiARw==', |
| 23 | # 'X-Amzn-Trace-Id': 'Root=1-5a1b28a6-2b6e5ef6657e0f5f2d671017', |
| 24 | # 'X-Forwarded-For': '75.82.111.45, 216.137.44.44', 'X-Forwarded-Port': '443', |
| 25 | # 'X-Forwarded-Proto': 'https'}, 'queryStringParameters': None, |
| 26 | # 'pathParameters': None, 'stageVariables': None, |
| 27 | # 'requestContext': {'requestTime': '26/Nov/2017:20:48:38 +0000', 'path': '/dev/asset', |
| 28 | # 'accountId': '818300131735', 'protocol': 'HTTP/1.1', |
| 29 | # 'resourceId': 'wpjmgf', 'stage': 'dev', 'requestTimeEpoch': 1511729318077, |
| 30 | # 'requestId': '2d827060-d2eb-11e7-96f5-9b58ecc94e3f', |
| 31 | # 'identity': {'cognitoIdentityPoolId': None, 'accountId': None, |
| 32 | # 'cognitoIdentityId': None, 'caller': None, 'apiKey': '', |
| 33 | # 'sourceIp': '75.82.111.45', 'accessKey': None, |
| 34 | # 'cognitoAuthenticationType': None, |
| 35 | # 'cognitoAuthenticationProvider': None, 'userArn': None, |
| 36 | # 'userAgent': 'curl/7.56.1', 'user': None}, |
| 37 | # 'resourcePath': '/asset', 'httpMethod': 'POST', 'apiId': 'c1xblyjsid'}, |
| 38 | # 'body': None, 'isBase64Encoded': False} |
| 39 | # |
| 40 | # _lambda_event = {'body': {}, 'method': 'POST', 'principalId': '', 'stage': 'dev', 'cognitoPoolClaims': {'sub': ''}, |
| 41 | # 'headers': {'Accept': '*/*', 'CloudFront-Forwarded-Proto': 'https', |
| 42 | # 'CloudFront-Is-Desktop-Viewer': 'true', 'CloudFront-Is-Mobile-Viewer': 'false', |
| 43 | # 'CloudFront-Is-SmartTV-Viewer': 'false', 'CloudFront-Is-Tablet-Viewer': 'false', |
| 44 | # 'CloudFront-Viewer-Country': 'US', |
| 45 | # 'Host': 'c1xblyjsid.execute-api.us-east-1.amazonaws.com', 'User-Agent': 'curl/7.56.1', |
| 46 | # 'Via': '1.1 022c901b294fedd7074704d46fce9819.cloudfront.net (CloudFront)', |
| 47 | # 'X-Amz-Cf-Id': 'BifKUMLw8qO30TNbJ4QObNGq6WVxiL9nTv9eMbRtAIqqHIqQDkZEVw==', |
| 48 | # 'X-Amzn-Trace-Id': 'Root=1-5a1b387c-47ab478111bbb2eb6bd6530c', |
| 49 | # 'X-Forwarded-For': '75.82.111.45, 216.137.44.14', 'X-Forwarded-Port': '443', |
| 50 | # 'X-Forwarded-Proto': 'https'}, 'query': {}, 'path': {}, |
| 51 | # 'identity': {'cognitoIdentityPoolId': '', 'accountId': '', 'cognitoIdentityId': '', 'caller': '', |
| 52 | # 'apiKey': '', 'sourceIp': '75.82.111.45', 'accessKey': '', |
| 53 | # 'cognitoAuthenticationType': '', 'cognitoAuthenticationProvider': '', 'userArn': '', |
| 54 | # 'userAgent': 'curl/7.56.1', 'user': ''}, 'stageVariables': {}} |
| 55 | |
| 56 | logger.debug('event: {}'.format(event)) |
| 57 | asset = AssetModel() |
| 58 | asset.asset_id = uuid.uuid1().__str__() |
| 59 | asset.save() |
| 60 | upload_url = asset.get_upload_url() # No timeout specified here, use member param default |
| 61 | |
| 62 | return { |
| 63 | "statusCode": httplib.CREATED, |
| 64 | "body": { |
nothing calls this directly
no test coverage detected