0.0.6 • Published 7 years ago
@serverless/sf v0.0.6
Serverless Framework V.2
"The future of cloud is outcomes, not infrastructure."
Get Started
Clone repo.
$ git clone https://github.com/serverless/v2.gitInstall dependencies.
cd v2 && npm i -gPick an example. Each example requires credentials for Amazon Web Services set as environment variables.
Serverless Framework V.2 supports .env files in the same folder as serverless.yml or serverless.js. Create one that looks like this:
AWS_ACCESS_KEY_ID=123456789
AWS_SECRET_ACCESS_KEY=987654321Run $ v2.
$ website: v2
✔ my-site
URL http://serverless-6vql3jp9.s3-website-us-east-1.amazonaws.com
3s › dev › my-site › DoneYou can leverage different environment variables for different stages by using this naming convention:
.env # Default
.env.dev
.env.prodHow To Use A Serverless Component Programmatically
Create a new javascript file, and load/use Components like this:
// To load a Component, instantiate it's class...
const realtimeApp = new RealtimeApp('instanceId', { /* inputs */ })
// To run/deploy/update a Component, call it's default function...
await realtimeApp()
// To run extra functionality, use custom methods that come w/ the Component...
await realtimeApp.loadTest()How To Use A Serverless Component Declaratively
Use a serverless.yml file, like this:
name: realtimeApp
stage: dev
providers:
AwsProvider::aws:
accessKeyId: ${secrets:aws_access_key_id}
secretAccessKey: ${secrets:secret_access_key}
components:
RealtimeApp::realtimeApp:
name: ${name}-${stage}
code: ./src/backendThen use your CLI, like this:
# To run/deploy/update all Components, call 'serverless'...
$ serverless
# To run extra functionality that comes with the a component, call this...
$ serverless loadTest myRealtimeApp
# To remove Components in YAML, call this...
$ serverless removeHow To Write A Serverless Component
Use a serverless.js file, like this:
class MyComponent extends Component {
/*
* Default (Required)
* - The default functionality to run/provision/update your Component
*/
async default() { }
/*
* Remove (Optional)
* - If your Component removes infrastructure, this is recommended.
*/
async remove() { }
}Created By
- Eslam Hefnawy - @eahefnawy
- Philipp Muens - @pmmuens