Alexa and Kubernetes: Deploying the Alexa Skill on AWS Elastic Kubernetes Services (VII)
In this article, we will continue discussing Alexa and Kubernetes, this time, how to deploy our Alexa Skill on AWS Elastic Kubernetes Services using Terraform.
Join the DZone community and get the full member experience.Join For Free
Now, we have everything prepared and ready to go to a Kubernetes Cluster in a cloud provider. It is a fact that creating a cluster in any cloud provider manually is a difficult task. Moreover, if we want to automate this deployment, we need something that helps us in this tedious task. In this article, we will see how to create a Kubernetes Cluster and all of its required objects and also, deploying our Alexa Skill with Terraform using Elastic Kubernetes Service.
Here, you have the technologies used in this project:
- Node.js v12.x
- Visual Studio Code
- Docker 19.x
- Kubectl CLI
- MongoDB Atlas Account
- go >=1.11
- Terraform 12.x
- AWS Account
- AWS CLI
- AWS IAM Authenticator CLI
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers, as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state. Then, it executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans, which can be applied.
The infrastructure Terraform includes low-level components, such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.
After the brief overview of Terraform, I am going to explain all of the terraform files and their objects that we are going to use to deploy the cluster and our Alexa Skill. You can find all the files related to this deployment in
A provider is responsible for understanding API interactions and exposing resources. Most of the available providers correspond to one cloud or on-premises infrastructure platform and offer resource types that correspond to each of the features of that platform.
For the Elastic Kubernetes Service, we will use the
aws provider. This provider allows us to create all of the AWS objects that we need to create our Alexa Skill Stack:
As we are going to deploy Helm Charts, it will be required to have the
As for the cluster, it will be useful to have the
Terraform Modules and Resources
One of the most important resources of an EKS Cluster is the networks. Because of that, we have to create our Virtual Private Cloud Network and Subnetworks. For that, we need to use the
Once the Private cloud Network has been created, we can create the cluster that we will use for that VPC. For that, we need to use the
Moreover, we will create some specific AWS IAM Policies to our Kubernetes Cluster Nodes in order to be reachable from the internet. For that, we will use the
All of the resources and modules commented on above are related to the Kubernetes cluster. Now, it’s time to deploy our Alexa Skill starting with the
After that, we can proudly deploy our Alexa Skill Helm chart in our Kubernetes Cloud cluster:
We have provided some variables that you can modify easily in order to change the name of the cluster or the region where the cluster will be deployed. For that, you can modify the local variables on
Deploying the Stack
In order to make a provider available on Terraform, we need to make a
terraform init. These commands download any plugins we need for our providers. After that, we have to execute
The terraform plan command is used to create an execution plan. It will not modify things in infrastructure. Terraform performs a refresh unless explicitly disabled and then, it determines what actions are necessary to achieve the desired state specified in the configuration files. This command is a convenient way to check whether the execution plan for a set of changes matches your expectations without making any changes to real resources or to the state. Then, we need to execute
terraform apply. The terraform apply command is used to apply the changes required to reach the desired state of the configuration. Terraform apply will also write data to the terraform.tfstate file. Once the application is completed, resources are immediately available.
Here, you have the full command list:
After running the
terraform apply, we can take a look at the Elastic Kubernetes Service to see that our cluster now appears.
We need to wait about 10 minutes until the cluster is created. Once the cluster is created, now we can see the full specifications.
After the cluster creation, Terraform will deploy all the Helm charts. There, you can see all the Kubernetes Pods deployed.
And, there, we can see the Kubernetes Services and the external IP of the
nginx-ingress-controller. That IP is the one we are going to use to make Alexa requests.
I’m sure you already know the famous tool call Postman. REST APIs have become the new standard in providing a public and secure interface for your service. Though REST has become ubiquitous, it’s not always easy to test. Postman makes it easier to test and manage HTTP REST APIs. Postman gives us multiple features to import, test, and share APIs, which will help you and your team be more productive in the long run.
After running your application, you will have an endpoint available here. With Postman, you can emulate any Alexa Request.
For example, you can test a
Destroy the Stack
If we want to remove all the stack created by Terraform, just run:
- The Official Node.js SDK Documentation
- Official Alexa Skills Kit Documentation
- Express Adapter Documentation
- Kind Documentation
- Kubernetes Documentation
- Terraform EKS
- Terraform EKS GitHub
Now, we have our Alexa Skill running in a Kubernetes Cluster of our cloud provider with everything automated with Terraform; it's ready to use in our live Alexa Skills.
I hope this example project is useful to you.
You can find the code here.
That’s all folks! Happy coding!
Opinions expressed by DZone contributors are their own.