Deploying to AWS using Terraform
So far we've tested our program locally using our Wing Console. Next we'll see how you can deploy your program to AWS using Terraform.
Wing compiler supports multiple targets
The Wing compiler supports multiple compilation targets. Each resource in the
Wing ecosystem can support any number of backends. For example, the
cloud.Queue resource we used in our app can be backed by Amazon
SQS by Azure Queue
Storage or by
RabbitMQ by CloudAMQP.
A target represents both the cloud provider and the provisioning engine. For
tf-aws target will compile your program to a set of AWS
resources, using Terraform as the provisioning engine.
🚧 We plan to support AWS, Azure and Google Cloud as targets out of the box. In addition, we are planning support for other provisioning engines such as AWS CloudFormation and Kubernetes.
Click 👍 on the relevant issue and tell us what you think.
Compile to Terraform/AWS
We will use the
tf-aws target to tell the compiler to bind all of our resources
to the default set of AWS resources and use Terraform as the provisioning engine.
wing compile --target tf-aws hello.w
Examine the output
Our target directory now contains a
cdktf.out directory which is the output of
CDK for Terraform used under
the hood to produce the Terraform configuration for this application.
Initialize Terraform state
Now, let's deploy our program to AWS.
You will need to have AWS credentials configured on your system. See here for more information.
Let's change the working directory to where our Terraform configuration is and initialize the state file:
export AWS_REGION=us-east-1 # or any other region
Now we are ready to deploy to our AWS account:
You'll be asked to confirm the provisioning of all of these resources:
This is a good opportunity to observe how much complexity the Wing compiler was able to abstract away for you when you wrote your Wing code. Just saying...
And Terraform will do its magic and will create all of these resources in your account.
Apply complete! Resources: 8 added, 0 changed, 0 destroyed.
Explore your app on AWS
After our application has been deployed to AWS, you should be able to interact with it through the AWS Management Console.
- Open the Amazon SQS Console
- Select your AWS region
- You should be able to see that you have a queue there
- Click Send and receive messages.
- In the Message Body box type
cloudand hit Send message.
- Jump over to the S3 Console
- There should be some buckets prefixed with
- Cycle through the buckets until you find one that contains
wing.txtthen click the
- The file should contain