bref: Internal server error after download on s3 bucket from aws lambda , PHP
I created aws lambda function based on laravel framework using bref. Link: https://bref.sh
this is my code to download using media library spartie
$mediaItem = Media::where('model_id',$id)->where('model_type','App\MODEL')->first();
return $mediaItem;
My configuration is
AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX
AWS_SECRET_ACCESS_KEY=XXXXX+XXXXXXXX
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=my-bucket
When I download file locally all work perfectly, but when I try to download on s3 in lambda function I got error:
{ “message” : “Internal server error” }
I use this package aws:
league/flysystem-aws-s3-v3 ~1.0
my serverless.yaml
service: serverless-api
provider:
name: aws
region: eu-central-1
runtime: provided
environment:
APP_ENV: production
iamRoleStatements:
- Effect: Allow
Action:
- s3:*
Resource: 'arn:aws:s3:::bucket/*'
plugins:
- ./vendor/bref/bref
package:
exclude:
- node_modules/**
- public/storage
- storage/**
- tests/**
- .env
functions:
website:
handler: public/index.php
timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
layers:
- arn:aws:lambda:eu-central-1:209497400698:layer:php-72-fpm:23
events:
- http: 'ANY /'
- http: 'ANY /{proxy+}'
artisan:
handler: artisan
timeout: 120 # in seconds
layers:
- arn:aws:lambda:eu-central-1:209497400698:layer:php-72:22
- arn:aws:lambda:eu-central-1:209497400698:layer:console:22
also i assign role for s3 , But I have no idea how it’s the problem .
thank you .
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (3 by maintainers)
Hi everybody , first of all thanks for your time for helping me . Finally I’ve found the solution , I am running the function lambda in a vpc , but the vpc does not have permission to access the s3 service so I followed this guide.
https://aws.amazon.com/es/blogs/aws/new-vpc-endpoint-for-amazon-s3/
and I ran into another error , By default API Gateway does not support binary HTTP requests or responses like images, PDF, binary files .
so I changed the serverless.yml like the documentation of bref
and now it works perfectly .
Thanks so much