ubaniabalogun/serverless-package-python-functions

Function names to include 'stage' in name?

sepulworld opened this issue · 2 comments

From what I have gathered Serverless normally includes the 'stage' (dev, stage, prod, etc.) that you provide in the function name. This defaults to 'dev' if you don't provide the --stage flag.

With serverless-package-python-functions the stage is left out of the function name it appears. So, if I use the same serverless.yml but do serverless deploy --stage dev and then serverless deploy --stage prod the function names overlap.

$ serverless deploy --stage prod
Serverless: [serverless-package-python-functions] Packaging set_office_hours...
Serverless: [serverless-package-python-functions] Packaging get_office_hours...
Serverless: [serverless-package-python-functions] Packaging add_discussion_topic...
Serverless: [serverless-package-python-functions] Packaging lookup_discussion_topics...
Serverless: Packaging service...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.............
Serverless: Deployment failed!

  Serverless Error ---------------------------------------

  An error occurred while provisioning your stack: GetUnderscoreofficeUnderscorehoursLogGroup - /aws/lambda/get_office_hours already exists in stack arn:aws:cloudformation:us-east-1:<REDACT>:stack/oh-bot-dev/5ee62430-65e0-11e7-87e8-50d5ca6326ba.

Did you leave the 'stage' out of the target.name on purpose? Or do you think this is something I could add in a PR perhaps?

Hey @sepulworld.
Good catch! The reason the stage doesn't currently appear with the function name is that unless target.name is explicitly set, it won't exist when the plugin runs, meaning the default serverless behavior of tacking-on the default won't hold.

It's something that can be added easily enough via a PR. If you're interested in tackling it, please open a dummy PR and reference this issue while you work on the implementation so I and others can know it's being addressed. Here's the portion of the code you'd want to take a look at

selectAll() {
const functions = this.serverless.service.functions
const info = _.map(functions, (target) => {
return {
name: target.name,
includes: target.package.include
}
})
return info
}

I'd recommend implementing the feature as an opt-in flag.

This issue has been addressed by a change in documentation