Miserlou / Zappa

Serverless Python
https://blog.zappa.io/
MIT License
11.89k stars 1.2k forks source link

Feature: .zappa_defaults.py #1064

Open scoates opened 7 years ago

scoates commented 7 years ago

It would be helpful if we could provide incomplete/default values to add to the zappa_settings.json on zappa init.

Context

For my public projects, I've provided zappa_settings.example.json which requires the developer to manually merge in and collate defaults. This is not ideal.

It would be interesting if the developer could provide a data structure to populate these defaults or ask the user to provide specific values.

For example, for paste.website, I have this zappa_settings.example.json:

{
    "v1": {
        "app_function": "app.app",
        "domain": "paste.example.com",
        "s3_bucket": "ADDME",
        "remote_env_bucket": "ADDME",
        "remote_env_file": "ADDME",
        "memory_size": 128,
        "project_name": "Example Paste Web Site",
    }
}

But it would be nice if the user could do zappa init, and as part of its execution could ask users for these fields. Additionally, it would be even nicer if zappa could run some python code to help calculate these values (for things that are determined locally).

Consider this ".zappa_defaults.py":

import subprocess
# defaults for zappa settings
app_function = "app.app"
domain = None  # no default; ask user
# don't bother asking about s3_bucket ; let Zappa do the default
remote_env_bucket = None
remote_env_file = "pastewebsite-config.json"
memory_size = 128
project_name = subprocess.check_output(["whoami"]).rstrip() + "'s paste web site"

Then zappa init would ask about each of these, providing the default (if not None) as the default for the user to just press enter, outputting the results to zappa_settings.json, upon completion.


If there's interest, I can work on this a bit.

Miserlou commented 7 years ago

Hmmmmmmmmmmmmmm.

On one hand, I'm strongly opposed to new forms of cruft. On the other hand, I do like the idea of people being able to distribute Zappa applications which are able to intelligently zappa init. I could see this being a good way to set environment variables in project init that could be used inside an application, but how does init handle lists/dicts?

Curious what other people think about this. I think I'm open to it.

RevolutionTech commented 6 years ago

I also have a public project that could benefit from something like this. Currently I have a certificate ARN in zappa_settings.json that I don't really want to share, so I am currently encrypting the whole file and committing that instead.

It would certainly be nice though to be able to provide an incomplete settings file without the actual ARN, and then have a zappa init step that would ask for the ARN. Then zappa init would use the provided input and the incomplete settings file to generate a complete zappa_settings.json file locally.