Resolves matter 1 of https://github.com/serverless/serverless/issues/1895 Allow each function to declare the ARN of the role that it is to execute within. If any function has no role ARN but provider role ARN is defined then use that role for such functions. If any function does not have a specified role (even by falling back to a provider-wide role) then add the default policy and role so that it can be used for such functions. Break out the portions of the logic into their discrete units so that the plugin code is a readable summary. Add comments to the discrete units. Add tests that check that the default role and policy are not added if every function has a role. Add tests that check that every function that has a declared role gets it assigned. Add tests that check that every function that has no declared role but where a provider role is declared gets the provider role assigned.
Deploy
This plugin (re)deploys the service to AWS.
How it works
Deploy starts by hooking into the deploy:setupProviderConfiguration lifecycle.
It fetches the basic CloudFormation template from lib/templates and replaces the necessary names and definitions
with the one it gets from the serverless.yml file.
Next up it deploys the CloudFormation template (which only includes the Serverless S3 deployment bucket) to AWS.
In the end it hooks into deploy:deploy lifecycle to update the previously created stack.
The resources section of the serverless.yml file is parsed and merged into the CloudFormation template.
This makes sure that custom resources the user has defined inside the serverless.yml file are added correctly.
Note: Empty, but defined Resources or Outputs sections are set to an empty object before being merged.
Next up it removes old service directories (with its files) in the services S3 bucket. After that it creates a new directory
with the current time as the directory name in S3 and uploads the services artifacts (e.g. the .zip file and the CloudFormation
file) in this directory. Furthermore it updates the stack with all the Resources which are defined in
serverless.service.resources.Resources (this also includes the custom provider resources).
The stack status is checked every 5 seconds with the help of the CloudFormation API. It will return a success message if
the stack status is CREATE_COMPLETE or UPDATE_COMPLETE (depends if you deploy your service for the first time or
redeploy it after making some changes).