Skip to content

s3 event schema#8330

Merged
medikoo merged 34 commits into
serverless:masterfrom
thewizarodofoz:aws-s3-event-schema
Oct 30, 2020
Merged

s3 event schema#8330
medikoo merged 34 commits into
serverless:masterfrom
thewizarodofoz:aws-s3-event-schema

Conversation

@thewizarodofoz

Copy link
Copy Markdown
Contributor

Closes: #8031

@codecov-commenter

codecov-commenter commented Oct 2, 2020

Copy link
Copy Markdown

Codecov Report

Merging #8330 into master will decrease coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8330      +/-   ##
==========================================
- Coverage   88.01%   88.01%   -0.01%     
==========================================
  Files         249      249              
  Lines        9307     9306       -1     
==========================================
- Hits         8192     8191       -1     
  Misses       1115     1115              
Impacted Files Coverage Δ
...ib/plugins/aws/package/compile/events/sns/index.js 100.00% <ø> (ø)
lib/plugins/aws/package/compile/functions/index.js 96.64% <ø> (-0.02%) ⬇️
lib/plugins/aws/provider/awsProvider.js 93.04% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a020a4a...fbed014. Read the comment docs.

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz ! It looks promising. Please see my comments.

Also (I forgot to initially note in dedicated issue, sorry for that). We need to also define s3 block at provider section. It supports name, and all this properties:

'accelerateConfiguration',
'accessControl',
'analyticsConfigurations',
'bucketEncryption',
'bucketName',
'corsConfiguration',
'inventoryConfigurations',
'lifecycleConfiguration',
'loggingConfiguration',
'metricsConfigurations',
'notificationConfiguration',
'objectLockConfiguration',
'objectLockEnabled',
'publicAccessBlockConfiguration',
'replicationConfiguration',
'tags',
'versioningConfiguration',
'websiteConfiguration',
(having that defined in schema, we can remove that allowed properties validation)

Comment thread lib/plugins/aws/package/compile/events/s3/index.js Outdated
Comment thread lib/plugins/aws/package/compile/events/s3/index.js
Comment thread lib/plugins/aws/package/compile/events/s3/index.js
@thewizarodofoz

thewizarodofoz commented Oct 3, 2020

Copy link
Copy Markdown
Contributor Author

We need to also define s3 block at provider section

@medikoo do you mean you would like to see a full fledged schema of all the bucket properties? Or just a validation for the allowed properties?

@medikoo

medikoo commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

@medikoo do you mean you would like to see a full fledged schema of all the bucket properties?

I think it's similar case to CloudFront, where we take CF template properties one by one. So I would do same as there. So introduce proper schema for each property

@thewizarodofoz
thewizarodofoz marked this pull request as draft October 11, 2020 12:09
@thewizarodofoz
thewizarodofoz marked this pull request as ready for review October 11, 2020 13:28
@codecov-io

codecov-io commented Oct 11, 2020

Copy link
Copy Markdown

Codecov Report

Merging #8330 into master will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8330      +/-   ##
==========================================
- Coverage   87.39%   87.36%   -0.04%     
==========================================
  Files         254      255       +1     
  Lines        9476     9461      -15     
==========================================
- Hits         8282     8266      -16     
- Misses       1194     1195       +1     
Impacted Files Coverage Δ
lib/classes/ConfigSchemaHandler/index.js 90.00% <ø> (+0.43%) ⬆️
lib/plugins/aws/provider/awsProvider.js 93.43% <ø> (ø)
...gins/aws/package/compile/events/s3/configSchema.js 100.00% <100.00%> (ø)
lib/plugins/aws/package/compile/events/s3/index.js 98.48% <100.00%> (-1.52%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b6ae44e...673f776. Read the comment docs.

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@thewizarodofoz Thank you! That looks very promising. Still I believe we should maintain convention with which other schemas are configured. Please see my comment.

If convention can be improved, I would first discuss and eventually refactor with other PR already existing schemas into new convention before adapting to new one in this PR

serverless.setProvider('aws', new AwsProvider(serverless));
awsCompileS3Events = new AwsCompileS3Events(serverless);
awsCompileS3Events.serverless.service.service = 'new-service';
// TODO: remove awsS3BucketName.pattern stub when tests are refactored to use runServerless

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can remove this comment, as converting to runServerless means not writing this stub at all (a kind of test where AwsCompileS3Events instance is created individually)

Comment thread lib/plugins/aws/provider/awsProvider.js Outdated
},
additionalProperties: false,
},
s3: require('./lib/s3/Bucket'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Moving this out, breaks the convention. All others properties are defined inline, and this one is not, why exactly?

If there's no specific reason, I would keep it inline with other schema.

It's also way easier for inspection, which can be common when users may want to investigate why they receive the schema errors

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will move the top bucket schema inline.
How do you feel about all other sub-schemas in seperate files and required by ./lib/s3/Bucket.js?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think all of them should be inline (or are they reusable across different places?)

Eventually all could be in one external s3.js file, but with that I would also move few other big blocks into separate external files (eg. definitions, functions, layers, resources`) - and that will be better to first handle in separate PR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is quite a lot of reuse of sub schemas. So having it all inline will require repetition.
I vote for moving all s3 related schemas into a single s3.js file which will be required by awsProvider.js and externalise other big blocks in a later PR.

@medikoo medikoo Oct 14, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is quite a lot of reuse of sub schemas. So having it all inline will require repetition.

In such case we may reference them in local env vars (we already do that in some places)

I vote for moving all s3 related schemas into a single s3.js file which will be required by awsProvider.js and externalise other big blocks in a later PR.

I'm fine with that, still let's put it in lib/plugins/aws/package/compile/events/s3/configSchema.js (the only file, with reusable parts organized via local vars)

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @thewizarodofoz for update ! Still, I've just noticed that as configured, schema intended for provider.s3 is not really attached.

It'll be nice to confirm that it works testing it against some invalid s3 event configuration

Also can you double check that s3 integration tests pass (see instructions: https://github.com/serverless/serverless/tree/master/test#aws-integration-tests ), e.g. when adding schema for provider.apiGateway we've introduced some bugs that got exposed by those tests (I've already fixed them with #8399 and #8400)

Thank you!

Comment thread lib/plugins/aws/provider/awsProvider.js Outdated
},
additionalProperties: false,
},
s3: require('../package/compile/events/s3/configSchema'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here it's in effective, it needs to be in provider.properties group.

@medikoo

medikoo commented Oct 16, 2020

Copy link
Copy Markdown
Contributor

One more thing: In so far schemas I've converted most of oneOf to anyOf, as it doesn't play well in some cases with implied coercion, also it's more optimal for checking, as with oneOf AJV will always validate against each option, while with anyOf it'll stop at first matched.

Therefore I think it'll be nice to also adapt to it in context of this PR

@thewizarodofoz

Copy link
Copy Markdown
Contributor Author

Screen Shot 2020-10-16 at 17 43 39

Integration tests pass (ran them all once, and then s3 alone)

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz that's impressive!

I've spotted just few last issues. Also if I see correctly, it's the last missing schema (yay!).

Therefore I believe we also should remove this:

if (this.serverless.service.provider.name === 'aws') {
// TODO: Remove after provider is fully covered, see https://github.com/serverless/serverless/issues/8022
this.serverless.configSchemaHandler.relaxAwsProviderSchema();
}
(together with relaxAwsProviderSchema method implementation)

enum: ['DEEP_ARCHIVE', 'GLACIER', 'INTELLIGENT_TIERING', 'ONEZONE_IA', 'STANDARD_IA'],
},
TransitionInDays: {
type: 'integer',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think in such cases where natural number is expected, it'll be good to add minimum: 0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok.
the only place I left without min 0 is ReplicationRule.Priority because maybe one can de-prioritise a rule by setting a negative priority.

type: 'array',
items: tagFilter,
},
transition,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's remove that one, as it's deprecated (also it's casing is not right)

Comment on lines +431 to +455
AllowedHeaders: {
type: 'array',
items: { type: 'string' },
},
AllowedMethods: {
type: 'array',
items: { enum: ['GET', 'PUT', 'HEAD', 'POST', 'DELETE'] },
},
AllowedOrigins: {
type: 'array',
items: { type: 'string' },
},
ExposedHeaders: {
type: 'array',
items: { type: 'string' },
},
Id: {
type: 'string',
maxLength: 255,
},
MaxAge: {
type: 'integer',
},
},
required: ['AllowedMethods', 'AllowedOrigins'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@thewizarodofoz

thewizarodofoz commented Oct 20, 2020

Copy link
Copy Markdown
Contributor Author

@medikoo after removing relaxAwsProviderSchema two tests are failing (one, two). They both use a field deploymentBucketObject which is not part of the schema.
They used to pass because relaxAwsProviderSchema was setting additionalProperties = true.
This field is not documented so I'm not sure what to do about it. Please advise.

@medikoo

medikoo commented Oct 27, 2020

Copy link
Copy Markdown
Contributor

@medikoo after removing relaxAwsProviderSchema two tests are failing (one, two). They both use a field deploymentBucketObject which is not part of the schema.

@thewizarodofoz sorry for late response. It's errors in tests. I've fixed them in #8447, so now issue should be gone,

@thewizarodofoz

Copy link
Copy Markdown
Contributor Author

Thanks @medikoo, unfortunately I don't think it solved it.
It seems awsProvider is populating deploymentBucketObject prior to the validation, so when we validate the schema we still encounter the issue.

@medikoo

medikoo commented Oct 29, 2020

Copy link
Copy Markdown
Contributor

It seems awsProvider is populating deploymentBucketObject prior to the validation, so when we validate the schema we still encounter the issue.

@thewizarodofoz Indeed there was an error as we've taken modified provider input for validation. I've fixed that here: #8450

I believe all should be fine now

@medikoo medikoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @thewizarodofoz !

@medikoo
medikoo merged commit 61d8ee9 into serverless:master Oct 30, 2020
@thewizarodofoz
thewizarodofoz deleted the aws-s3-event-schema branch October 30, 2020 19:18
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.36%. Comparing base (b6ae44e) to head (673f776).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8330      +/-   ##
==========================================
- Coverage   87.39%   87.36%   -0.04%     
==========================================
  Files         254      255       +1     
  Lines        9476     9461      -15     
==========================================
- Hits         8282     8266      -16     
- Misses       1194     1195       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Config schema: Define AWS "s3" function event properties

4 participants