sapessi / serverless-sam

Serverless framework plugin to export AWS SAM templates for a service
Apache License 2.0
152 stars 26 forks source link

Bug Fix: Supports multiple runtimes within the same serverless.yml #25

Closed NRaf closed 6 years ago

NRaf commented 6 years ago

Submitting this PR to fix an issue I've encountered.

In my example, all my functions are written in Java however I had a use-case where I need one function written in NodeJS.

To get it to work with Serverless, I need to do the following:

With these changes, everything works as expected when I deploy to AWS, however when I exported the SAM template and attempted to run it locally using sam local-api it would try to execute the NodeJS handler using the Java image.

The reason for this is that the code that gets the Runtime and CodeUri doesn't take into account parameters defined at a function-level.

I've put in a simple fix to give precedence to the runtime and artifact set at a function level over the top-level runtime / artifact.

itsthatianguy commented 6 years ago

Just ran into this same problem when putting together an example project using Node, Java and Python - hopefully this can be merged soon 🙂

sapessi commented 6 years ago

Hey @ianrufus, will this conflict with PR #27? Out of curiosity, what's your use-case for SAM local vs the serverless framwork's serverless-offline plugin?

Can we add a test for this?

itsthatianguy commented 6 years ago

The serverless-offline plugin says it only works with NodeJS on the project readme - our work has been primarily in Java and Python, so we've been using SAM Local to use API Gateway with those runtimes locally. I've not had anything to do with the changes made by this PR, but I can try and take a look later this week if @NRaf doesn't have time