Comments (4)
@Tlapi
Here is a great documentation on how to create and push the docker Lambda container image.
https://docs.aws.amazon.com/lambda/latest/dg/images-create.html
Here is the all the dependencies from the requirements.txt so you don't need to install it and pip freeze
flatbuffers==23.3.3
humanfriendly==10.0
mpmath==1.3.0
numpy==1.23.5
onnxruntime==1.13.1
opencv-python-headless==4.6.0.66
packaging==23.1
Pillow==9.3.0
protobuf==4.22.3
rembg-aws-lambda==0.2.0
sympy==1.11.1
Note:
If using Mac M chips for building the image use this decorator --platform linux/amd64
docker build -t hello-world . --platform linux/amd64
Example of Lambda function to read from the S3 bucket get the image, process it with rembg and upload it to a different folder on the same bucket.
import boto3
from rembg import remove
# Initialize boto3 to use the S3 client.
s3_client = boto3.client('s3')
def lambda_handler(event, context):
try:
# Get the file inside the S3 Bucket
s3_response = s3_client.get_object(
Bucket='<Bucket-Name>',
Key='public/image-test.jpg'
)
# Get the Body object in the S3 get_object() response
s3_object_body = s3_response.get('Body')
# Read the data in bytes format
content_str = s3_object_body.read()
# Remove background with rembg
input = content_str
output = remove(input)
#put object in different directory
response = s3_client.put_object(Body=output, Bucket='<Bucket-Name>', Key='public/processed/image-test.jpg')
return response
except s3_client.exceptions.NoSuchBucket as e:
# S3 Bucket does not exist
print('The S3 bucket does not exist.')
print(e)
except s3_client.exceptions.NoSuchKey as e:
# Object does not exist in the S3 Bucket
print('The S3 objects does not exist in the S3 bucket.')
print(e)
from rembg-aws-lambda.
Hi @Tlapi, thanks for opening issue! I definitely agree that adding documentation on usage in an AWS lambda environment would be useful for other devs to get started.
I've personally used a Dockerfile
for deployment as a container-based lambda, but I agree that documenting this approach (or adding a sample Dockerfile
in the docs) would definitely be beneficial for others.
P.S. It's been a while since I've used the serverless framework, so I might need some help/PR with ensuring that the docs correctly outline such a use case.
from rembg-aws-lambda.
This issue is stale because it has been open for 30 days with no activity.
from rembg-aws-lambda.
This issue was closed because it has been inactive for 14 days since being marked as stale.
from rembg-aws-lambda.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rembg-aws-lambda.