All the steps requires you to have AWS CLI installed.
It also needs your credentials to be set inside ~/.aws/credentials
. If your profile isn't the default profile don't forget to specify it when it's necessary.
Make sure you have Serverless installed.
All you have to do is deploying the app with the following command (default profile):
$ serverless deploy
If you want to specify the AWS profile:
$ serverless deploy --aws-profile $profileName
Considering that the API is in python, you'll have to create python files. For good development purpose, you will have to create a new folder if you want to add a new type of routes (e.g.: users):
$ mkdir users
You can now create python file inside this new folder. Because our route will be AWS Lambda, you don't have to create a main function.
You can open serverless.yml:
$ nano serverless.yml
At the end of the file you will find the functions
part.
You can add the following part to the yml file in functions part:
...
users:
handler: users/users.get_users # folder/py_file/function_name
events:
- http:
path: users # path to the route
method: get # method to use (get, post, delete...)
Note: A route with authorization mean that if you want to call the route you will have to put an Authorization
in the header of the request where the value is the tokenID provided by Cognito.
You can add the following part to the yml file in functions part:
...
users:
handler: users/users.delete_user
events:
- http:
path: users/{id}
method: delete
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: ApiGatewayAuthorizer