Improve AWS credential handling, documentation and onboarding
For users without prior knowledge of AWS its hard to understand how to get credentials in place to get started with using AWS.
This negatively influences the onboarding experience as users don't really know how to even get started. We need to have better documentation and potentially a simple onboarding command that could either set credentials or validate them.
Tasks:
- [ ] Improve documentation on AWS documentation
- [ ] Discuss onboarding command that could help with credentials
something like:
sls setup --provider aws --key XYZ --secret ABC
- this checks the
.aws/credentialsexist - if it exists, it checks for for [default] credentials block and then adds it if it doesn't exist
2a. doesn't exist create
.aws/credentials, then run 2.
Basically a wrapper for this process https://github.com/serverless/serverless/blob/v1.0/docs/guide/provider-account-setup.md
The sls setup command is meant to streamline EVERY part of the external provider setup process we can to get users TTFD (Time to first deploy ©) as quick as possible.
(some stuff like creating initial IAM role in AWS are out of our control)
Related: https://github.com/serverless/serverless/issues/1727
The current docs read like a long tutorial. This sounded nice in the beginning, but I no longer use the docs because concepts are discussed gradually, in multiple places, and I can't tell where to go to find the single source of truth. Instead, I dig into the source code to find that single source of truth. Given the overall large amount of configuration in a serverless architecture, I think the "it's-all-a-tutorial" approach should be avoided in favor of docs designed for easy referencing.
Also, the current docs have a nested tables of contents pattern, which seems excessive, makes me feel like I have to click around too much, and gives me the general feeling of being constantly lost.
IMO, these problems could be solved by shallower organization and clearer separation of concerns.
Proposal for an improved doc structure:
Quick Start: // This section is provider agnostic, concise and simply lists the commands, outlining the entire workflow
- Installing Serverless
- Creating Services
- Deploying Services
- Invoking Functions
- Removing Services
- Installing Plugins
- Creating Plugins
Core Concepts: // High-Level definitions of core concepts
- Services
- Functions
- Events
- Resources
- Environment (stages, regions & vars)
- Plugins
Configuration: // Provider-specific configuration details and examples
- AWS Services
- Functions
- Events
- S3
- Schedule
- HTTP
- Resources
- Other
- Azure Services
Tutorials: // Contributors can add tutorials on how to do specific things with the Framework.
Credit to @eahefnawy for coming up with most of this.
@DavidWells +1 Later, we can see if people want to persist other profiles with this command too. But right now, keeping it simple and focused on only creating the default profile will help a lot.
@nikgraf I think I remember you having an issue with the credentials too. If I'm not mistaken, do you have any thoughts about this?
I really like the serverless setupcommand. Additionally I would make this work a little bit different so that it will be automatically run when the user enters another command but has not yet setup his credentials.
E.g. he enters serverless create. Then Serverless will check if the credentials are setup and if not will prompt the setup steps. This way the user has not to run the setup process by hand.
Here's a link to another issue which discusses a new doc structure we've talked about the other day https://github.com/serverless/serverless/issues/1522
RE: current docs - At the moment, I'm trying hard to find how VPC support works in serverless.yml, but it's not obvious where to look. I've clicked around for a few minutes now. No luck.
@ac360 Here is some documentation: https://github.com/serverless/serverless/blob/v1.0/docs/guide/deploying-a-service.md#deploying-vpc-configuration-for-lambda
This will not work since the Iam Role doesn't have the necessary permission. I assume this isn't fully supported by serverless yet.
The Lambda function execution role must have permissions to create ENIs. AWS Lambda provides a permissions policy,
AWSLambdaVPCAccessExecutionRole, with permissions for the necessary EC2 actions (ec2:CreateNetworkInterface,ec2:DescribeNetworkInterfaces, andec2:DeleteNetworkInterface) that you can use when creating a role. You can review the policy in the IAM console.Source: http://docs.aws.amazon.com/lambda/latest/dg/vpc.html
Thank you, @estahn. I found it. The point is just to demonstrate that there is no obvious place to look. Sticking VPC config into the deploying a service section is confusing. There should be one place to look to see all AWS config details for serverless.yml. Much easier to maintain too.
@ac360 I agree.
Please consider also accepting the environment variable-based configuration of credentials in the same manner as the AWS CLI and SDKS. This helps those of us who use the Secure Token Service to assume roles in other accounts.
See http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment
@ac360 Should we create a separate ticket for the Iam Role issue?
@chalfant we do support this. We're using the official AWS Node SDK and it should pull those environment variables: https://github.com/serverless/serverless/blob/master/docs/guide/provider-account-setup.md Let us know in case this doesn't work
@estahn there is an issue created for it in #1535
I've just moved this up in priority so we can get this up and running fast. Shouldn't be too hard I think
@flomotlik Excellent. I'll give it a try.
What about multi profile support? Atm it's only possible to use the default profile right?
@estahn @chalfant We've just implemented custom IAM policy support on master: https://github.com/serverless/serverless/pull/1749
@nicka you can use --profile to use a different profile that is defined in your ~/.aws/credentials file
@flomotlik Awesome 🍻
@nicka sorry I mixed something up there, we don't currently have --profile in the framework. Here you can see the implementation for aws where it selects the profiles. You can set them through the default environment variables though.
Would be interesting to have --profile support as well, shouldn't be too hard. Probably just looking for the profile option and if its set use that one.
Here is the code btw: https://github.com/serverless/serverless/blob/990d7c5a089c2047cdd342fca88f6c006c53c4c3/lib/plugins/aws/index.js#L73
@flomotlik I see!
Confirmed, it works when I specify an AWS_PROFILE environment variable. This could also be part of the proposed .env support within #1707.
Currently profiles are not used when configured in the serverless.env.yml
stages:
dev:
vars:
profile: test
It is injected currently as such:
new AWS[service]({ region: "ap-southeast-2", profile: "test" )
That does nothing.
Seems like you need to actually do it this way:
var credentials = new AWS.SharedIniFileCredentials({profile: 'work-stuff'});
AWS.config.credentials = credentials;
See: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
Hey @samdj thanks for chiming in!
Yes, we're currently rethinking the whole environment variable handling in this issue: https://github.com/serverless/serverless/issues/1801 Happy to have your feedback on this one!
Furthermore there's a feature in the making which makes it easier to switch between profiles: https://github.com/serverless/serverless/issues/1787 (Also happy to have your feedback here!)
Hope that makes everything a little bit more clear. Otherwise just drop a line 👍