To let the Serverless Framework access your AWS account, we're going to create an IAM User with Admin access, which can configure the services in your AWS account. This IAM User will have its own set of AWS Access Keys.
sls config credentials --provider aws --key XXXXXXXXXXXXEXAMPLE --secret XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXEXAMPLEKEY Serverless: Setting up AWS... Serverless: Saving your AWS profile in "~/.aws/credentials"... Serverless: Success! Your AWS access keys were stored under the "default" profile.
$ sls create --help Plugin: Create create ........................ Create new Serverless service --template / -t (required) ......... Template for the service. Available templates: "aws-nodejs", "aws-python", "aws-java-maven", "aws-java-gradle", "aws-scala-sbt", "aws-csharp", "openwhisk-nodejs" and "plugin" --path / -p ........................ The path where the service should be created (e.g. --path my-service) --name / -n ........................ Name for the service. Overwrites the default name of the created service.
$ cd slstest/ $ sls deploy Serverless: Creating Stack... Serverless: Checking Stack create progress... ..... Serverless: Stack create finished... Serverless: Packaging service... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading service .zip file to S3 (639 B)... Serverless: Updating Stack... Serverless: Checking Stack update progress... .................. Serverless: Stack update finished... Service Information service: slstest stage: dev region: us-east-1 api keys: None endpoints: None functions: slstest-dev-hello
这样就deploy好了,里面自动设定好了CloudFormation,IAM,Lambda等.
测试一下
deploy之后测试一下
1 2 3 4 5
$ sls invoke -f hello { "body": "{\"input\": {}, \"message\": \"Go Serverless v1.0! Your function executed successfully!\"}", "statusCode": 200 }
测试也非常简单.sls invoke的命令行:
1 2 3 4 5 6 7 8 9 10 11
$ sls invoke --help Plugin: Invoke invoke ........................ Invoke a deployed function invoke local .................. Invoke function locally --function / -f (required) ......... The function name --stage / -s ....................... Stage of the service --region / -r ...................... Region of the service --path / -p ........................ Path to JSON or YAML file holding input data --type / -t ........................ Type of invocation --log / -l ......................... Trigger logging data output --data / -d ........................ input data