Skip to content

fix(parser): Update S3 Event Schema #3671

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

Merged
merged 3 commits into from
Feb 27, 2025
Merged
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
4 changes: 2 additions & 2 deletions packages/parser/src/schemas/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const S3Identity = z.object({
});

const S3RequestParameters = z.object({
sourceIPAddress: z.string().ip(),
sourceIPAddress: z.union([z.string().ip(), z.literal('s3.amazonaws.com')]),
});

const S3ResponseElements = z.object({
Expand All @@ -24,7 +24,7 @@ const S3Message = z.object({
size: z.number().optional(),
urlDecodedKey: z.string().optional(),
eTag: z.string().optional(),
sequencer: z.string(),
sequencer: z.string().optional(), // Only present in PUT and DELETE events
versionId: z.optional(z.string()),
}),
bucket: z.object({
Expand Down
36 changes: 36 additions & 0 deletions packages/parser/tests/events/s3/s3-lifecycle-event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Records": [
{
"eventVersion": "2.3",
"eventSource": "aws:s3",
"awsRegion": "us-west-2",
"eventTime": "1970-01-01T00:00:00.000Z",
"eventName": "LifecycleExpiration:Delete",
"userIdentity": {
"principalId": "s3.amazonaws.com"
},
"requestParameters": {
"sourceIPAddress": "s3.amazonaws.com"
},
"responseElements": {
"x-amz-request-id": "C3D13FE58DE4C810",
"x-amz-id-2": "FMyUVURIY8/IgAtTv8xRjskZQpcIZ9KG4V5Wp6S7S/JRWeUWerMUE5JgHvANOjpD"
},
"s3": {
"s3SchemaVersion": "1.0",
"configurationId": "testConfigRule",
"bucket": {
"name": "amzn-s3-demo-bucket",
"ownerIdentity": {
"principalId": "A3NL1KOZZKExample"
},
"arn": "arn:aws:s3:::amzn-s3-demo-bucket"
},
"object": {
"key": "expiration/delete",
"sequencer": "0055AED6DCD90281E5"
}
}
}
]
}
14 changes: 14 additions & 0 deletions packages/parser/tests/unit/schema/s3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ describe('Schema: S3', () => {
expect(result).toStrictEqual(event);
});

it('parses an S3 LifeCycle event with a deleted object', () => {
// Prepare
const event = getTestEvent<S3Event>({
eventsPath,
filename: 's3-lifecycle-event',
});

// Act
const result = S3Schema.parse(event);

// Assess
expect(result).toStrictEqual(event);
});

it('parses an S3 Object Lambda with an IAM user', () => {
// Prepare
const event = structuredClone(baseLambdaEvent);
Expand Down
Loading