Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,17 @@
kms_key=kms_stack.kms_key,
)

# Create the S3 bucket stack for public profile avatars, passing the Lambda function
# Create the S3 bucket stack for public profile avatars, passing the
# Lambda function
s3_profile_avatar_public_stack = ProfileAvatarPublicBucketStack(
app,
f"{APP_STACK_PREFIX}ProfileAvatarPublicBucketStack",
env=environment,
lambda_fn=profile_avatar_resize_and_store_stack.lambda_fn,
)

# Create the S3 bucket stack for profile avatar uploads, passing the Lambda function
# Create the S3 bucket stack for profile avatar uploads, passing the
# Lambda function
s3_profile_avatar_upload_stack = ProfileAvatarUploadBucketStack(
app,
f"{APP_STACK_PREFIX}ProfileAvatarUploadBucketStack",
Expand Down
82 changes: 41 additions & 41 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pytest = "^8.4.1"
aws-cdk-lib = "^2.206.0"
pydantic = "^2.11.7"
pyjwt = "^2.10.1"
cryptography = "^45.0.5"
cryptography = "^45.0.6"
requests = "^2.32.4"
pillow = "^11.3.0"

Expand Down
1 change: 1 addition & 0 deletions src/functions/profile_avatar_resize_and_store/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PIL import Image
import tempfile


def handler(event, context):
# Get bucket and key from event
record = event['Records'][0]
Expand Down
7 changes: 4 additions & 3 deletions stacks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .lambda_profile_avatar_resize_and_store import ProfileAvatarResizeAndStoreLambdaStack

__all__ = [
"KmsStack", "ProfileAvatarUploadBucketStack", "ProfileAvatarPublicBucketStack",
"ProfileAvatarResizeAndStoreLambdaStack"
]
"KmsStack",
"ProfileAvatarUploadBucketStack",
"ProfileAvatarPublicBucketStack",
"ProfileAvatarResizeAndStoreLambdaStack"]
9 changes: 4 additions & 5 deletions stacks/kms_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
"kms:GenerateDataKey",
],
resources=["*"],
principals=[iam.ServicePrincipal("lambda.amazonaws.com")],
principals=[
iam.ServicePrincipal("lambda.amazonaws.com")],
conditions={
"StringEquals": {
"kms:CallerAccount": self.account,
"kms:ViaService": f"lambda.{self.region}.amazonaws.com",
}
},
)
)
}},
))
10 changes: 8 additions & 2 deletions stacks/lambda_profile_avatar_resize_and_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@


class ProfileAvatarResizeAndStoreLambdaStack(Stack):
def __init__(self, scope: Construct, construct_id: str, kms_key, **kwargs) -> None:
def __init__(
self,
scope: Construct,
construct_id: str,
kms_key,
**kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

pillow_layer = _lambda.LayerVersion.from_layer_version_arn(
Expand All @@ -23,7 +28,8 @@ def __init__(self, scope: Construct, construct_id: str, kms_key, **kwargs) -> No
"ProfileAvatarResizeAndStoreLambda",
runtime=_lambda.Runtime.PYTHON_3_12,
handler="__init__.handler",
code=_lambda.Code.from_asset("src/functions/profile_avatar_resize_and_store"),
code=_lambda.Code.from_asset(
"src/functions/profile_avatar_resize_and_store"),
timeout=cdk.Duration.seconds(30),
memory_size=128,
layers=[pillow_layer],
Expand Down
8 changes: 7 additions & 1 deletion stacks/s3_profile_avatar_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
)
from constructs import Construct


class ProfileAvatarPublicBucketStack(Stack):
def __init__(self, scope: Construct, construct_id: str, lambda_fn=None, **kwargs) -> None:
def __init__(
self,
scope: Construct,
construct_id: str,
lambda_fn=None,
**kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)

# Create a public S3 bucket for profile avatars
Expand Down