https://github.com/mahdadghasemian/serverless-tutorial-project
Some example to run serverless api (AWS)
https://github.com/mahdadghasemian/serverless-tutorial-project
Last synced: 2 months ago
JSON representation
Some example to run serverless api (AWS)
- Host: GitHub
- URL: https://github.com/mahdadghasemian/serverless-tutorial-project
- Owner: MahdadGhasemian
- License: mit
- Created: 2023-12-04T12:35:12.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-11T08:08:11.000Z (over 1 year ago)
- Last Synced: 2025-02-04T16:14:48.019Z (4 months ago)
- Language: JavaScript
- Size: 723 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# serverless-tutorial-project
Some example to run serverless api (AWS)
# How to deploy:
* npm i
* npm i -g serverless
* serverless config credentials --provider aws --key YOUR_AWS_KEY --secret YOUR_AWS_SECRET --profile serverlessUser
* sls deploy# Create new project:
* npm init -y
* npm i -g serverless
* serverless config credentials --provider aws --key YOUR_AWS_KEY --secret YOUR_AWS_SECRET --profile serverlessUser
* serverless create --template aws-nodejs --path new-serverless-project# Branches
## Basic
#### api keys:
- x-api-key-free: the api key where returned after `sls deploy`
- x-api-key-paid: the api key where returned after `sls deploy`#### endpoints:
- GET - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-user/{ID}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-user/1234' \
--header 'x-api-key: returned_api_key'
```- GET - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-player-score/{ID}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-user/1234' \
--header 'x-api-key: returned_api_key'
```- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/create-player-score/{ID}
```bash
curl --location --request POST 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/create-player-score/4521545' \
--header 'Content-Type: application/json' \
--data-raw '{
"Name": "Sarah",
"Score": 15
}'
```- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/create-file/{fileName}
```bash
curl --location --request POST 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/create-file/car2.json' \
--header 'Content-Type: application/json' \
--data-raw '{
"color": "Red"
}'
```- GET - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-file/{fileName}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-file/car2.json'
```- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/send-email
```bash
curl --location --request POST 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/send-email' \
--header 'Content-Type: application/json' \
--data-raw '{
"to": "[email protected]",
"from": "[email protected]",
"subject": "Test Email",
"text": "Hi there, this is a message sent through my API"
}'
```- ANY - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/chuck-norris/{proxy+}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/chuck-norris/ANY'
```## Websocket
#### endpoints:
- WSS - wss://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev
#### online tool for testing:
- https://websocketking.com/
#### example json data to send
```json
{ "message": "Hey this is a websocket message!", "action": "message" }
```## SMS
#### endpoints:
- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/send-sms
```bash
curl --location --request POST 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/send-sms' \
--header 'Content-Type: application/json' \
--data-raw '{
"phoneNumber": "+your-phone-number",
"message": "This is a message from my serverless API!"
}'
```## Comprehend
#### endpoints:
- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/analyse
```bash
curl --location --request POST 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/analyse' \
--header 'Content-Type: application/json' \
--data-raw '{
"text": "This is a simple text to test the api"
}'
```## Cron
[Cron Format](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-cron-expressions.html)
[News API](https://newsapi.org/)## ReactApp
## Hooks
- The 'createPlayerScore.js' and 'getPlayerScore.js' files have been changed to use hooks.
## Update Dynamodb
- PUT - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/update-player-score/{ID}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-player-score/1234'
```## Query
#### endpoint:
- GET - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-game-scores/{game}
```bash
curl --location --request GET 'https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-game-scores/gamename'
```## Step Functions
#### Data for test execution
```json
{
"signup": {
"email": "[email protected]"
}
}
```
## Telegram Bot (Lex)
#### endpoint:
- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/telegram-webhook
#### Telegram:
Channel name to create a bot: "@botfather"
botname format: yourBootNameBot
username format: yourBootName_Bot
api: xxxxx_your_telegram_api
set-webhook:
```bash
curl --request POST \
--url https://api.telegram.org/botxxxxx_your_telegram_api/setWebhook \
--header 'content-type: application/json' \
--data '{"url": "https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/telegram-webhook"}'
```
**Note:** If you encounter an error as follows, you can switch to the old console (**AWS Lex console 1**)
- There is no alias named dev for the bot named botTelegram. Choose another alias## Image upload
#### endpoint:
- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/image-upload
#### Webpage to test
[upload page](https://sls-image-upload-test-bucket.s3-eu-west-1.amazonaws.com/index.html)## Image upload and resize
#### endpoint:
- POST - https://xxxxxxx.execute-api.us-east-1.amazonaws.com/dev/image-upload
#### Webpage to test
[upload page](https://sls-image-upload-test-bucket.s3-eu-west-1.amazonaws.com/index.html)