https://github.com/gamadorh/serverless-hello-world
Hello World application with Serverless Framework.
https://github.com/gamadorh/serverless-hello-world
aws example hello-world nodejs serverless serverless-framework
Last synced: about 1 month ago
JSON representation
Hello World application with Serverless Framework.
- Host: GitHub
- URL: https://github.com/gamadorh/serverless-hello-world
- Owner: gAmadorH
- License: mit
- Created: 2021-01-08T01:01:30.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-27T20:10:21.000Z (about 5 years ago)
- Last Synced: 2025-01-21T21:13:11.298Z (about 1 year ago)
- Topics: aws, example, hello-world, nodejs, serverless, serverless-framework
- Language: JavaScript
- Homepage:
- Size: 166 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serverless-hello-world

[](https://coveralls.io/github/gAmadorH/serverless-hello-world?branch=main)
[](https://david-dm.org/gAmadorH/serverless-hello-world)
[](https://david-dm.org/gAmadorH/serverless-hello-world#info=devDependencies)
[](https://github.com/gAmadorH/serverless-hello-world/blob/main/LICENSE)
[](https://eslint.org/)
[](https://github.com/airbnb/javascript)
[](https://github.com/gAmadorH/serverless-hello-world/issues)
Hello World application with Serverless Framework.
## requirements
- [NodeJS v12.18.3+](https://nodejs.org/en/) or [nvm v0.37.0+](https://github.com/nvm-sh/nvm/releases/tag/v0.37.0)
- [AWS Account](https://aws.amazon.com/)
- Access Key Id (key)
- Secret Access Key (secret)
## Install serverless framework
Install globally `serverless framework` using npm:
```bash
npm i -g serverless
```
Now you can use it with `serverless` or `sls` command in your terminal.
## Config serverless framework credentials
Config serverless framework credentials (AWS as provider):
```bash
sls config credentials \
--provider aws \
--key your-aws-key \
--secret your-aws-secret
```
This command has configured the AWS credentials in the `default profile`.
You can use the `--profile` flag to specific a profile.
`development` profile for example:
```bash
sls config credentials \
--provider aws \
--profile development \
--key your-aws-key \
--secret your-aws-secret
```
## Create a project boilerplate
Create a project directory and use a template:
```bash
mkdir serverless-test && cd $_
sls create --template aws-nodejs --name serverless-test
```
It has created 2 files, `serverless.yml` and h`handler.js`
the last file has a hello function, it does not a trigger event associated
then we have to add it, we are going yo use a http event,
so add this (in the `hello` function in the `serverless.yml` file):
```yml
events:
- http:
method: get
path: /hello
```
The files should look like this:
```yml
service: serverless-test
frameworkVersion: "2"
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
functions:
hello:
handler: handler.hello
events:
- http:
method: get
path: /hello
```
## Deploy your project
To deploy your new function run (using default profile):
```bash
sls deploy
```
If you want to use other profile, you can specify using `--aws-profile` option:
```bash
sls deploy --aws-profile development
```
When you execute the command, information about your service appears in your terminal,
look for `endpoints:` key, it looks something like this:
```bash
endpoints:
GET - https://something.execute-api.us-east-1.amazonaws.com/dev/hello
```
Now you can hit in the API endpoint:
```bash
curl https://something.execute-api.us-east-1.amazonaws.com/dev/hello
```
## Watch logs
To watch logs run:
```bash
sls logs -t -f hello
# or
sls logs --tail --function hello
```
The function name is defined in the `serverless.yml`:
```yml
functions:
hello: # this is the function name
handler: handler.hello
```
## Destroy
To destroy the infrastructure created by serverless framework run:
```bash
sls remove
```
## License
[MIT.](./LICENSE) Copyright (c)