Skip to main content

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 example, the tf-aws target will compile your program to a set of AWS resources, using Terraform as the provisioning engine.

Under Construction

🚧 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.

Credentials Required

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:

cd ./target/hello.tfaws
export AWS_REGION=us-east-1 # or any other region
terraform init

Terraform deploy

Now we are ready to deploy to our AWS account:

terraform apply

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.

  1. Open the Amazon SQS Console
  2. Select your AWS region
  3. You should be able to see that you have a queue there
  4. Click Send and receive messages.
  5. In the Message Body box type cloud and hit Send message.
  6. Jump over to the S3 Console
  7. There should be some buckets prefixed with terraform-202.
  8. Cycle through the buckets until you find one that contains wing.txt.
  9. Click wing.txt then click the Open button.
  10. The file should contain Hello, cloud.