Skip to content

feat: Addition of Amazon S3 Event Notifications #245

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Install pipenv
run: |
Expand Down
11 changes: 11 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.12"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Doing serverless with Terraform? Check out [serverless.tf framework](https://ser

## Supported Features

- AWS Lambda runtime Python 3.11
- AWS Lambda runtime Python 3.12
- Create new SNS topic or use existing one
- Support plaintext and encrypted version of Slack webhook URL
- Most of Slack message options are customizable
Expand Down Expand Up @@ -37,11 +37,11 @@ module "notify_slack" {

[Terraform Cloud Agents](https://www.terraform.io/docs/cloud/workspaces/agent.html) are a paid feature, available as part of the Terraform Cloud for Business upgrade package.

This module requires Python 3.11. You can customize [tfc-agent](https://hub.docker.com/r/hashicorp/tfc-agent) to include Python using this sample `Dockerfile`:
This module requires Python 3.12. You can customize [tfc-agent](https://hub.docker.com/r/hashicorp/tfc-agent) to include Python using this sample `Dockerfile`:

```Dockerfile
FROM hashicorp/tfc-agent:latest
RUN apt-get -y update && apt-get -y install python3.11 python3-pip
RUN apt-get -y update && apt-get -y install python3.12 python3-pip
ENTRYPOINT ["/bin/tfc-agent"]
```

Expand Down
4 changes: 3 additions & 1 deletion functions/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ verify_ssl = true
name = "pypi"

[packages]
boto3 = "*"
pytest = "*"

[dev-packages]
boto3 = "~=1.34"
Expand All @@ -18,7 +20,7 @@ radon = "*"
snapshottest = "~=0.6"

[requires]
python_version = "3.11"
python_version = "3.12"

[scripts]
test = "python3 -m pytest --cov --cov-report=term"
Expand Down
36 changes: 36 additions & 0 deletions functions/events/s3_object_acl_put_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Records": [
{
"eventVersion": "2.3",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-13T21:24:59.306Z",
"eventName": "ObjectAcl:Put",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "XXXXXXXXXXXXXXXX",
"x-amz-id-2": "kJnocM4etuvc6BN1KT31BpAydhXF+3krucrYYGydPe44CasqrjWd4QM28pRvGM4Sg8T/IldaDqYrhD3TiOBDvIMSzwufbDO6"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "test",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"eTag": "24979f2d8bb004928be4e6d87888f857"
}
}
}
]
}
39 changes: 39 additions & 0 deletions functions/events/s3_object_creation_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T14:44:56.042Z",
"eventName": "ObjectCreated:CompleteMultipartUpload",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "22HVMTY7K7BZEANW",
"x-amz-id-2": "7JNov8pldcSneqm8P52a3uaVaI5E+X3EPgnFcHUOta5iC2VHORDQlkOHa3pghQY9Px5p7RgphoJAu6EZFzKVWft3PHccuUhC"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"size": 557056,
"eTag": "7d347f0d62d856c4dceef44b413b5bb2-1",
"versionId": "2EkRWHmQowiCXIVHSfD48cKVfS87iBZ4",
"sequencer": "00657871E7BEB1C11D"
}
}
}
]
}
38 changes: 38 additions & 0 deletions functions/events/s3_object_delete_marker_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T15:43:47.889Z",
"eventName": "ObjectRemoved:DeleteMarkerCreated",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "FSFTKP0F7F4GAYJ7",
"x-amz-id-2": "DLuIxXz8rgdn14lRySy0xePLTs+LL+3Azm4bpGudx7Bqax+t7bWUdKMUuJQf/lmXDaaUEnG+e67kEI4/kdI2LzAI/D+XXUnK"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"eTag": "d41d8cd98f00b204e9800998ecf8427e",
"versionId": "4hWOOw8KrqaXtuiI9NpQzoFNDmnnlJlw",
"sequencer": "0065787FB3DCA9D828"
}
}
}
]
}
37 changes: 37 additions & 0 deletions functions/events/s3_object_put_tag_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Records": [
{
"eventVersion": "2.3",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T16:57:37.808Z",
"eventName": "ObjectTagging:Put",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "CC3E1ZWK9W1X12HF",
"x-amz-id-2": "aXF6jUEXS9805Oa5ZTQgoXJCzUMt0ZCi/vRaB8EQK9O/b723Ct9A/oeAiF/U92GEnA5/cJ1ZUcyo0NSmOqVyaHq1jKz+rSF+"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"eTag": "6dfa2bd9148dd380b5d56bd1366787f6",
"versionId": "wzGflBz2kJXzspA4UQ0Ik333dbvePdnP"
}
}
}
]
}
37 changes: 37 additions & 0 deletions functions/events/s3_object_removal_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T17:04:47.117Z",
"eventName": "ObjectRemoved:Delete",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "E3MKJZCF0A5CKYQB",
"x-amz-id-2": "2qsHsa9aFfq+oOIl837VxPlE/Xq3Ii2hQ9p3WaCXF22cwSoH1gtg9K0u86hDy8BdorKhpiR0dA/9VSQ2TFoeSAkZ1vH6/kZO"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"versionId": "sSHvWiZd1mM73EqLISh8ammc3JresZcC",
"sequencer": "00657892AF1C2D606B"
}
}
}
]
}
46 changes: 46 additions & 0 deletions functions/events/s3_object_replication_failure.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"Records": [
{
"eventVersion": "2.2",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T17:04:56.129Z",
"eventName": "Replication:OperationFailedReplication",
"userIdentity": {
"principalId": "s3.amazonaws.com"
},
"requestParameters": {
"sourceIPAddress": "s3.amazonaws.com"
},
"responseElements": {
"x-amz-request-id": "a8f51c21-9f7d-4619-b54f-eb6577b67a82",
"x-amz-id-2": "4cWlLlh7RJD8eHJfb7EKfNnnSiDiZjvRBUMPl5rq5wsCSiRF+QePRr0nW9ku2wd2eOJc0TBxf27AxAbL9Irl0A=="
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "111222333444"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"size": 1024,
"eTag": "d41d8cd98f00b204e9800998ecf8427e",
"versionId": "sSHvWiZd1mM73EqLISh8ammc3JresZcC",
"sequencer": "00657892A0790CB714"
}
},
"replicationEventData": {
"replicationRuleId": "Replication",
"destinationBucket": "arn:aws:s3:::test-replica",
"s3Operation": "OBJECT_DELETE",
"requestTime": "2024-12-12T17:04:32.489Z",
"failureReason": "SrcObjectNotFound"
}
}
]
}
39 changes: 39 additions & 0 deletions functions/messages/s3_object_notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"Records": [
{
"eventVersion": "2.1",
"eventSource": "aws:s3",
"awsRegion": "eu-west-1",
"eventTime": "2024-12-12T14:44:56.042Z",
"eventName": "ObjectCreated:CompleteMultipartUpload",
"userIdentity": {
"principalId": "AWS:AXXXXXXXXXXXXXXXXXXXX:test"
},
"requestParameters": {
"sourceIPAddress": "1.1.1.1"
},
"responseElements": {
"x-amz-request-id": "22HVMTY7K7BZEANW",
"x-amz-id-2": "7JNov8pldcSneqm8P52a3uaVaI5E+X3EPgnFcHUOta5iC2VHORDQlkOHa3pghQY9Px5p7RgphoJAu6EZFzKVWft3PHccuUhC"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "backup",
"bucket": {
"name": "test",
"ownerIdentity": {
"principalId": "AXXXXXXXXXXXXX"
},
"arn": "arn:aws:s3:::test"
},
"object": {
"key": "test.png",
"size": 557056,
"eTag": "7d347f0d62d856c4dceef44b413b5bb2-1",
"versionId": "2EkRWHmQowiCXIVHSfD48cKVfS87iBZ4",
"sequencer": "00657871E7BEB1C11D"
}
}
}
]
}
Loading
Loading