Skip to content

Commit

Permalink
fix: Fixed lambda infinite loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kojicmarko committed Mar 11, 2024
1 parent 1f9eaba commit 9ef0e59
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lambda_handlers/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ def lambda_handler(event, context):
download_path = f"/tmp/{os.path.basename(key)}"
client.download_file(bucket, key, download_path)

client.delete_object(Bucket=bucket, Key=key)

with Image.open(download_path) as img:
img.thumbnail((400, 400))

img.save(download_path)

client.upload_file(download_path, bucket, key)
new_key = key.replace("logos/", "resized_logos/")
client.upload_file(download_path, bucket, new_key)
7 changes: 4 additions & 3 deletions src/logos/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def create(
user: user_schemas.User,
db: Session,
) -> logo_schemas.Logo:
url = s3.upload(logo_file, project.id, "logos")
unprocessed_url = s3.upload(logo_file, project.id, "logos")
url = unprocessed_url.replace("logos", "resized_logos")

logo = logo_models.Logo(name=str(logo_file.filename), url=url, owner_id=user.id)

Expand All @@ -42,7 +43,7 @@ def create(
def update(
logo: logo_models.Logo, proj_id: UUID, file: UploadFile, db: Session
) -> logo_schemas.Logo:
s3.delete(f"{proj_id}_{logo.name}", "logos")
s3.delete(f"{proj_id}_{logo.name}", "resized_logos")

logo.name = str(file.filename)
logo.url = s3.upload(file, proj_id, "logos")
Expand All @@ -65,6 +66,6 @@ def delete(
detail="Only Project owner can delete the Logo",
)

s3.delete(f"{project.id}_{logo.name}", "logos")
s3.delete(f"{project.id}_{logo.name}", "resized_logos")
db.delete(logo)
db.commit()
2 changes: 1 addition & 1 deletion src/projects/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def delete(project: proj_models.Project, owner_id: UUID, db: Session) -> None:

if project.logo_id:
logo = get_logo_by_id(project.id, db)
s3.delete(f"{project.id}_{logo.name}", "logos")
s3.delete(f"{project.id}_{logo.name}", "resized_logos")

db.delete(project)
db.commit()
Expand Down

0 comments on commit 9ef0e59

Please sign in to comment.