Repository: Miserlou/Zappa

Issue:
slim_handler "current_project" file is same name regardless of stage deployed
## Context
When setting "slim_handler" : True in the configuration file, for each stage, it appears that the "current_project" file created in the s3 bucket is the same name regardless of stage.  

Apologies if this isn't an issue.  But it seems like based on how I read the documentation for slim handler that it could cause bugs.  If we had two stages deployed that use slim handler, then we update one stage using zappa update, there is a chance that the other stage could pick up the change. I'm assuming it would pick up the change if it wasn't 'warm' and had to reload the code using the s3 bucket...and I'm assuming the "current_project" file represents the code that put aside by having slim handler set to true.

Python 2.7 (probably 3.6 too) and using a virtual environment.

## Expected Behavior
The "current_project" file should be unique for each stage.

## Actual Behavior
The "current_project" file is not unique for each stage.

## Possible Fix
Make the "current_project" file unique for each stage.
Workaround - Make a unique s3 bucket for each stage.
Might be nice to a have a separate s3 bucket config for holding code used by slim handler.

## Steps to Reproduce
1.  A zappa settings file with two stages, each stage has the slim_handler set to True.
2. Deploy one stage.  Check the s3 bucket.  The current project file will have a name of "<project_name>_current_project.tar.gz". 
3. Deploy the second stage.  The current project file, mention in 2, is updated. 

## Your Environment
<!--- Include as many relevant details about the environment you experienced the bug in -->
* Zappa version used: 0.43.2
* Operating System and Python version: Mac os, python 2.7 & 3.6
* The output of `pip freeze`:
appdirs==1.4.3
argcomplete==1.8.2
base58==0.2.4
boto3==1.4.5
botocore==1.5.40
certifi==2017.7.27.1
chardet==3.0.4
click==6.7
coreapi==2.3.0
coreschema==0.0.4
cx-Oracle==5.3
Django==1.11
django-filter==1.0.2
django-rest-swagger==2.1.2
djangorestframework==3.6.2
docutils==0.14
durationpy==0.5
future==0.16.0
futures==3.1.1
hjson==3.0.0
idna==2.6
itypes==1.1.0
Jinja2==2.9.6
jmespath==0.9.3
kappa==0.6.0
lambda-packages==0.16.1
MarkupSafe==1.0
openapi-codec==1.3.1
packaging==16.8
placebo==0.8.1
psycopg2==2.7.1
pyparsing==2.2.0
python-dateutil==2.6.1
python-slugify==1.2.4
pytz==2017.2
PyYAML==3.12
requests==2.18.4
rollbar==0.13.12
s3transfer==0.1.10
simplejson==3.10.0
six==1.10.0
toml==0.9.2
tqdm==4.15.0
troposphere==1.9.5
Unidecode==0.4.21
uritemplate==3.0.0
urllib3==1.22
Werkzeug==0.12
wsgi-request-logger==0.4.6
zappa==0.43.2
* Link to your project (optional):
No
* Your `zappa_settings.py`: 
{
  "dev": {
    "project_name": "giving_drf",
    "role_name": "giving_drf_dev_role",
    "iam_authorization": true,
    "runtime": "python2.7",
    "manage_roles": false,
    "profile_name": "apps",
    "django_settings": "project_config.settings.dev",
    "slim_handler": true,
    "s3_bucket": "zappa-zip-deploy-apps-account",
    "callbacks": {
      "settings": "zappa.zappadeploycallbacks.settingscallback.settings_callback",
      "zip": "zappa.zappadeploycallbacks.zipcallback.zip_callback",
      "post": "zappa.zappadeploycallbacks.postcallback.post_callback"
    },
    "exclude": [
      "zappa.zappaforaws",
      "zappa.zappadeploycallbacks"
    ],
    "environment_variables": {
      "DEBUG_LOG_LEVEL": "DEBUG",
      /**/
      "SECRET_BUCKET": "835975970128014",
      "SECRET_FOLDER_FILE": "giving_drf/dev/settings.json"
    },
    "timeout_seconds": 300,
    /**/
    "vpc_config": {
      "SubnetIds": [
        "subnet-a847e885",
        "subnet-bac20886",
        /**/
        "subnet-f3983ba8",
        "subnet-4fb92706"
      ],
      "SecurityGroupIds": [
        /**/
        "sg-7c927300"
        /**/
      ]
    }
  },
  "test": {
    "project_name": "giving_drf",
    "role_name": "giving_drf_dev_role",
    "iam_authorization": true,
    "runtime": "python2.7",
    "manage_roles": false,
    "profile_name": "apps",
    "django_settings": "project_config.settings.test",
    "slim_handler": true,
    "s3_bucket": "zappa-zip-deploy-apps-account",
    "callbacks": {
      "settings": "zappa.zappadeploycallbacks.settingscallback.settings_callback",
      "zip": "zappa.zappadeploycallbacks.zipcallback.zip_callback",
      "post": "zappa.zappadeploycallbacks.postcallback.post_callback"
    },
    "exclude": [
      "zappa.zappaforaws",
      "zappa.zappadeploycallbacks"
    ],
    "environment_variables": {
      "DEBUG_LOG_LEVEL": "DEBUG",
      /**/
      "SECRET_BUCKET": "835975970128014",
      "SECRET_FOLDER_FILE": "giving_drf/dev/settings.json"
    },
    "timeout_seconds": 300,
    /**/
    "vpc_config": {
      "SubnetIds": [
        "subnet-a847e885",
        "subnet-bac20886",
        /**/
        "subnet-f3983ba8",
        "subnet-4fb92706"
      ],
      "SecurityGroupIds": [
        /**/
        "sg-7c927300"
        /**/
      ]
    }
  }
}





Discussion:

Resolving patch:
diff --git a/zappa/cli.py b/zappa/cli.py
--- a/zappa/cli.py
+++ b/zappa/cli.py
@@ -695,7 +695,7 @@ def deploy(self):
                 raise ClickException("Unable to upload handler to S3. Quitting.")
 
             # Copy the project zip to the current project zip
-            current_project_name = '{0!s}_current_project.tar.gz'.format(self.project_name)
+            current_project_name = '{0!s}_{1!s}_current_project.tar.gz'.format(self.api_stage, self.project_name)
             success = self.zappa.copy_on_s3(src_file_name=self.zip_path, dst_file_name=current_project_name,
                                             bucket_name=self.s3_bucket_name)
             if not success:  # pragma: no cover
@@ -2199,7 +2199,8 @@ def create_package(self, output=None):
 
             # If slim handler, path to project zip
             if self.stage_config.get('slim_handler', False):
-                settings_s += "ARCHIVE_PATH='s3://{0!s}/{1!s}_current_project.tar.gz'\n".format(self.s3_bucket_name, self.project_name)
+                settings_s += "ARCHIVE_PATH='s3://{0!s}/{1!s}_{2!s}_current_project.tar.gz'\n".format(
+                    self.s3_bucket_name, self.api_stage, self.project_name)
 
                 # since includes are for slim handler add the setting here by joining arbitrary list from zappa_settings file
                 # and tell the handler we are the slim_handler


Test patch: