Skip to content
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

Add S3ObjectLambdaEvent #536

Merged
merged 8 commits into from
Jan 6, 2024
Merged

Add S3ObjectLambdaEvent #536

merged 8 commits into from
Jan 6, 2024

Conversation

kdnakt
Copy link
Contributor

@kdnakt kdnakt commented Dec 17, 2023

Issue #, if available:

#525

Description of changes:

I used JSON files for testing, similar to the repository below.
https://github.com/awslabs/aws-lambda-rust-runtime/tree/main/lambda-events/src/fixtures

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Dec 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (50dbfb1) 72.93% compared to head (8005661) 72.93%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #536   +/-   ##
=======================================
  Coverage   72.93%   72.93%           
=======================================
  Files          26       26           
  Lines        1456     1456           
=======================================
  Hits         1062     1062           
  Misses        322      322           
  Partials       72       72           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bmoffatt bmoffatt added enhancement type/events issue or feature request related to the events package labels Dec 19, 2023
Comment on lines 15 to 33
type GetObjectContext struct {
InputS3Url string `json:"inputS3Url"`
OutputRoute string `json:"outputRoute"`
OutputToken string `json:"outputToken"`
}

type ListObjectsContext struct {
InputS3Url string `json:"inputS3Url"`
}

type ListObjectsV2Context struct {
InputS3Url string `json:"inputS3Url"`
}

type HeadObjectContext struct {
InputS3Url string `json:"inputS3Url"`
}

type Configuration struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the new structs in the PR should be prefixed with something like S3ObjectLambda, to avoid polluting the shared event namespace with very generic names like Configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, I added the prefix.

RequestToken: &event.GetObjectContext.OutputToken,
Body: strings.NewReader(string(jsonData)),
}
return svc.WriteGetObjectResponse(ctx, input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a glance this doesn't look right as an example return value.

Looking at the docs https://docs.aws.amazon.com/AmazonS3/latest/userguide/olap-writing-lambda.html#olap-headobject

I see python functions returning things like {statusCode: 200, <otherfields>} and at least on java function defined with a void return type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this function just to return error.

Comment on lines 15 to 64
type GetObjectContext struct {
InputS3Url string `json:"inputS3Url"`
OutputRoute string `json:"outputRoute"`
OutputToken string `json:"outputToken"`
}

type ListObjectsContext struct {
InputS3Url string `json:"inputS3Url"`
}

type ListObjectsV2Context struct {
InputS3Url string `json:"inputS3Url"`
}

type HeadObjectContext struct {
InputS3Url string `json:"inputS3Url"`
}

type S3ObjectLambdaConfiguration struct {
AccessPointARN string `json:"accessPointArn"`
SupportingAccessPointARN string `json:"supportingAccessPointArn"`
Payload string `json:"payload"`
}

type UserRequest struct {
URL string `json:"url"`
Headers map[string]string `json:"headers"`
}

type UserIdentity struct {
Type string `json:"type"`
PrincipalID string `json:"principalId"`
ARN string `json:"arn"`
AccountID string `json:"accountId"`
AccessKeyID string `json:"accessKeyId"`
SessionContext *SessionContext `json:"sessionContext,omitempty"`
}

type SessionContext struct {
Attributes map[string]string `json:"attributes"`
SessionIssuer *SessionIssuer `json:"sessionIssuer,omitempty"`
}

type SessionIssuer struct {
Type string `json:"type"`
PrincipalID string `json:"principalId"`
ARN string `json:"arn"`
AccountID string `json:"accountId"`
UserName string `json:"userName"`
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these structs should be prefixed with S3ObjectLambda

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed them!

Comment on lines +5 to +8
GetObjectContext *S3ObjectLambdaGetObjectContext `json:"getObjectContext,omitempty"`
ListObjectsContext *S3ObjectLambdaListObjectsContext `json:"listObjectsContext,omitempty"`
ListObjectsV2Context *S3ObjectLambdaListObjectsV2Context `json:"listObjectsV2Context,omitempty"`
HeadObjectContext *S3ObjectLambdaHeadObjectContext `json:"headObjectContext,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking for another reference for these fields. The documentation I found so far only shows getObjectContext

https://docs.aws.amazon.com/AmazonS3/latest/userguide/olap-event-context.html

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR for the rust event calavera/aws-lambda-events#127 didn't contain additional docs for List/Head object.

Guess I gotta check this by hand, or ask the service team for a pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad! I forgot that I referenced that exact documentation when reviewing one of your previous commits! #536 (comment)

}

type S3ObjectLambdaGetObjectContext struct {
InputS3Url string `json:"inputS3Url"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linter should have flagged this 🧐 Should be InputS3URL instead of InputS3Url

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I fixed them.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: @kdnakt it looks like the README.md was not updated with this change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for letting me know!
I'll create another pull request for that.

Copy link
Collaborator

@bmoffatt bmoffatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@bmoffatt bmoffatt merged commit 501c2f3 into aws:main Jan 6, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement type/events issue or feature request related to the events package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants