Skip to content

Conversation

@rohanpm
Copy link
Contributor

@rohanpm rohanpm commented Feb 27, 2020

  • Add a tox configuration for creating a deployment zip file, so there's a
    standard way of doing it
  • Add top-level export for lambda function, so that internal module structure
    doesn't influence AWS configs

See individual commits for more details.

Helps generate a deployment package.
Run "tox -e package" and the resulting package.zip is ready for
upload to AWS.

The deployment package is created using pip.
Previously, the relevant lambda function we want to use was located
at:

  cdn_lambda.functions.map_to_s3.map_to_s3.lambda_handler

...and this function name needs to be used when configuring the
lambda in AWS. Alternatively, one could create the deployment
package by zipping up cdn_lambda/functions/map_to_s3 rather than
the entire module and using a shorter name.

Either option there is cumbersome and leaks details about how the
modules are structured internally, which could lead to cases where
we have to make changes to the lambda function config because
we refactored some modules.

It seems more stable and maintainable if we make sure there are
top-level imports for anything we expect to be invoked as a lambda
function. We can use the convention of naming them after their
trigger to denote how they're expected to be used.

This means that the function intended to be used with origin request
events can now be accessed as:

  cdn_lambda.origin_request

...which is brief, easy to understand and easy to keep working even
if we change completely how the Python modules are arranged
internally.
@rohanpm rohanpm marked this pull request as ready for review February 27, 2020 06:45
@rohanpm rohanpm requested a review from negillett as a code owner February 27, 2020 06:45
@rohanpm
Copy link
Contributor Author

rohanpm commented Feb 27, 2020

@crungehottman @nathanegillett

The background here is that I was looking at the lambda functions which had been previously deployed, and saw for instance a 'map_to_s3.lambda_handler' which seems to require zipping up specifically the cdn_lambda/functions/map_to_s3 directory. It seems rather messy, e.g. it breaks normal Python import behavior (imagine if map_to_s3 imports some cdn_lambda.utils - it'll work fine for autotests in this repo, then break when you go to deploy it).

Copy link
Member

@negillett negillett left a comment

Choose a reason for hiding this comment

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

I think we'll likely have this done inside a pipeline but it may still prove helpful for local use.

@rohanpm rohanpm merged commit 4419ad3 into release-engineering:master Mar 4, 2020
@rohanpm rohanpm deleted the deployment branch March 4, 2020 04:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants