With Serverless, it's easier than ever to deploy production-ready API endpoints. However, using AWS API Gateway results in odd hostnames for your endpoints. Further, these hostnames will change if you remove and redeploy your service, which can cause problems for existing clients.
This project will help you set-up a mapping between custom domain name to your serverless endpoint.
Watch the video guide here or follow the steps below to create and deploy your first serverless microservice in minutes.
- Install serverless and serverless-domain-manager via npm:
# Install serverless
npm install -g serverless
# Install serverless-domain-manager
npm install serverless-domain-manager --save-dev
- Set-up your Provider Credentials.
Watch the video on setting up credentials
- Create DNS ZONE and Certificate
Update the config.yaml and domain.yaml files variables and set the project name, domain zone and cert name according to your project preferences.
Note that you'll need to keep the region to us-east-1 (N.Virginia) as this is the only region that works with API Gateway.
sceptre --dir ./aws-resources launch-env infrastructure
- Configure service:
Get created resources outputs
sceptre --dir ./aws-resources describe-stack-outputs infrastructure domain
Then update the env-vars.yaml properly according to the data outputted by the previous command.
- Create the custom domain:
serverless create_domain
- Deploy The Service:
Use the command below when you want to deploy your service or have made changes to your Functions, Events or Resources in serverless.yml
.
serverless deploy -v
-
Deploy a Function:
Use this to quickly upload and overwrite your AWS Lambda code on AWS, allowing you to develop faster.
serverless deploy function -f hello
-
Invoke a Function:
Invokes an AWS Lambda Function on AWS and returns logs.
serverless invoke -f hello -l
-
Fetch a Function Logs:
Open up a separate tab in your console and stream all logs for a specific Function using this command.
serverless logs -f hello -t
-
Remove the created custom domain:
serverless delete_domain
-
Remove the Service:
Removes all Functions, Events and Resources from your AWS account.
serverless remove