-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ETL-397] Create s3-event-config lambda and dependencies to add s3 notification configuration #50
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1594f37
initial design for new s3-event-config lambda and dep
d49ec81
add prod stacks
8032add
add prod stacks
a152f6a
add error catching, update docs due to lambda structure changes
50572e7
add namespace for s3 notification filtering
17e6e17
add tests for test_s3_event_config_lambda
43dad96
update s3 event config lambda readme
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ synapseclient = "~=2.7" | |
pandas = "<1.5" | ||
moto = "~=4.1" | ||
datacompy = "~=0.8" | ||
docker = "~=6.1" | ||
thomasyu888 marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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,67 @@ | ||
import zipfile | ||
import io | ||
import boto3 | ||
from moto import mock_s3, mock_lambda, mock_iam, mock_logs | ||
import pytest | ||
|
||
from src.lambda_function.s3_event_config import app | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def mock_iam_role(mock_aws_credentials): | ||
with mock_iam(): | ||
iam = boto3.client("iam") | ||
yield iam.create_role( | ||
RoleName="some-role", | ||
AssumeRolePolicyDocument="some policy", | ||
Path="/some-path/", | ||
)["Role"]["Arn"] | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def mock_lambda_function(mock_aws_credentials, mock_iam_role): | ||
with mock_lambda(): | ||
client = boto3.client("lambda") | ||
client.create_function( | ||
FunctionName="some_function", | ||
Role=mock_iam_role, | ||
Code={"ZipFile": "print('DONE')"}, | ||
Description="string", | ||
) | ||
yield client.get_function(FunctionName="some_function") | ||
|
||
|
||
@mock_s3 | ||
def test_that_add_notification_adds_expected_settings(s3, mock_lambda_function): | ||
s3.create_bucket(Bucket="some_bucket") | ||
set_config = app.add_notification( | ||
s3, | ||
mock_lambda_function["Configuration"]["FunctionArn"], | ||
"some_bucket", | ||
"test_folder", | ||
) | ||
get_config = s3.get_bucket_notification_configuration(Bucket="some_bucket") | ||
assert ( | ||
get_config["LambdaFunctionConfigurations"][0]["LambdaFunctionArn"] | ||
== mock_lambda_function["Configuration"]["FunctionArn"] | ||
) | ||
assert get_config["LambdaFunctionConfigurations"][0]["Events"] == [ | ||
"s3:ObjectCreated:*" | ||
] | ||
assert get_config["LambdaFunctionConfigurations"][0]["Filter"] == { | ||
"Key": {"FilterRules": [{"Name": "prefix", "Value": "test_folder"}]} | ||
} | ||
|
||
|
||
@mock_s3 | ||
def test_that_delete_notification_is_successful(s3, mock_lambda_function): | ||
s3.create_bucket(Bucket="some_bucket") | ||
app.add_notification( | ||
s3, | ||
mock_lambda_function["Configuration"]["FunctionArn"], | ||
"some_bucket", | ||
"test_folder", | ||
) | ||
app.delete_notification(s3, "some_bucket") | ||
get_config = s3.get_bucket_notification_configuration(Bucket="some_bucket") | ||
assert "LambdaFunctionConfigurations" not in get_config |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's dependency of using
mock_lambda
frommoto3
but for some reason installingmoto3
doesn't automatically installdocker
as a dependency