-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: example using S3 trigger for Lambda (#106)
- Loading branch information
Showing
7 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from aws_cdk import core | ||
|
||
from s3trigger.s3trigger_stack import S3TriggerStack | ||
|
||
app = core.App() | ||
S3TriggerStack(app, "s3trigger") | ||
|
||
app.synth() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "python3 app.py" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
def main(event, context): | ||
# save event to logs | ||
print(event) | ||
|
||
return { | ||
'statusCode': 200, | ||
'body': event | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
aws-cdk.core | ||
|
||
aws-cdk.aws-s3 | ||
aws-cdk.aws-lambda | ||
aws-cdk.aws_s3_notifications |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from aws_cdk import ( | ||
aws_lambda as _lambda, | ||
aws_s3 as _s3, | ||
aws_s3_notifications, | ||
core | ||
) | ||
|
||
|
||
class S3TriggerStack(core.Stack): | ||
|
||
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: | ||
super().__init__(scope, id, **kwargs) | ||
|
||
# create lambda function | ||
function = _lambda.Function(self, "lambda_function", | ||
runtime=_lambda.Runtime.PYTHON_3_7, | ||
handler="lambda-handler.main", | ||
code=_lambda.Code.asset("./lambda")) | ||
# create s3 bucket | ||
s3 = _s3.Bucket(self, "s3bucket") | ||
|
||
# create s3 notification for lambda function | ||
notification = aws_s3_notifications.LambdaDestination(function) | ||
|
||
# assign notification for the s3 event type (ex: OBJECT_CREATED) | ||
s3.add_event_notification(_s3.EventType.OBJECT_CREATED, notification) |