简体   繁体   中英

AWS lambda function with container working locally but not on aws

i have create a lambda function with container. The code work well when i test locally.

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations"  -d ......

But when i push it to ECR and deploy on lambda, it did not worked. Error is in the first line of code

with open(os.path.join('../tmp',video_name), 'wb') as f:
    s3_client.download_fileobj('mybucketname', video_name, f)

I dont know where the issue is Here is complete error

START RequestId: 5facecee-e48f-4575-beb8-8afb0710f3e5 Version: $LATEST
[ERROR] 2022-08-18T12:07:09.814Z    5facecee-e48f-4575-beb8-8afb0710f3e5    An error occurred running the application.
Traceback (most recent call last):
File "/var/task/mangum/protocols/http.py", line 58, in run
await app(self.scope, self.receive, self.send)
File "/var/task/fastapi/applications.py", line 269, in __call__
await super().__call__(scope, receive, send)
File "/var/task/starlette/applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "/var/task/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/var/task/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/var/task/starlette/exceptions.py", line 93, in __call__
raise exc
File "/var/task/starlette/exceptions.py", line 82, in __call__
await self.app(scope, receive, sender)
File "/var/task/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/var/task/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/var/task/starlette/routing.py", line 670, in __call__
await route.handle(scope, receive, send)
File "/var/task/starlette/routing.py", line 266, in handle
await self.app(scope, receive, send)
File "/var/task/starlette/routing.py", line 65, in app
response = await func(request)
File "/var/task/fastapi/routing.py", line 227, in app
raw_response = await run_endpoint_function(
File "/var/task/fastapi/routing.py", line 162, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "/var/task/starlette/concurrency.py", line 41, in run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "/var/task/anyio/to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "/var/task/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "/var/task/anyio/_backends/_asyncio.py", line 867, in run
result = context.run(func, *args)
File "/var/task/app.py", line 17, in read_item
download_video(video_name)
File "/var/task/botos3.py", line 9, in download_video
with open(os.path.join('../tmp',video_name), 'wb') as f:
END RequestId: 5facecee-e48f-4575-beb8-8afb0710f3e5

You need to change this:

with open(os.path.join('../tmp',video_name), 'wb') as f:

to this:

with open(os.path.join('/tmp',video_name), 'wb') as f:

Only /tmp is writeable in the AWS Lambda runtime environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM