Learn how to use Infrastructure as Code with Architect to deploy a lambda to your own AWS account in minutes.
If you haven't setup an AWS Account or the AWS CLI create an account at https://aws.amazon.com and follow this guide for setting up the CLI
Transcript
One of the quickest ways to deploy an app with infrastructure as code is using a tool called architect. So if you come to arc.codes and go to quick start we can just copy this command and then we can come into our terminal and we can run this command which is going to be called our app or your app. So it's going to install architect and once it's finished installing we will get a new app created with a lambda function. Okay so we can cd into your app and then we can open it in our code editor. Okay now if we come into source index this is an actual lambda function And the way that we can tell that is in this app.art file.
And in our manifest file, using these primitives, we can define handlers. So this is a get handler, and this creates a Lambda function for us. So back in our index, and we run npm start, and we can go back to our browser, and we can open localhost. We have our architect app up and running and one thing we can do is use these lambdas as API functions So I'm gonna replace this code with a little bit of code stop our server and install the architects functions package which will help us with creating handlers. Okay, now if I save this and run our app again, and we can come back to localhost, we get our message, hello from the public API.
So we can change this message and say, hello from our architect, Lambda. And come back to our app, and our message has updated. So now we can deploy this app. To deploy you need to have the AWS CLI set up and configured for your AWS account and I have my lambda console pulled up and so you can see currently I have no lambda function so if we come back and we can say vx arc deploy so it's going to deploy it to us-west2 it's going to install and hydrate generate cloud formation, and deploy and build the infrastructure. And once this is done, we can go into our AWS console and look at our Lambda functions, and we will see a new Lambda function deployed.
Okay and now our Lambda function has been deployed and to test this out we can come to our dashboard again and refresh and we see we have a Lambda function within AWS. And then if we come back and click on the URL that we were given, and open and we see we get our hello from our architect Lambda. Okay. Now if we come back into our lambda and we probably don't want to keep this silly little lambda alive so we can go ahead and destroy our lambda with npx arc destroy and we'll have to pass it a few flags since it created a lambda and s3 bucket we'll say dash app your app and then we'll say force okay and now that lambda is destroyed So if we come back to our dashboard and refresh, we see we don't have a Lambda anymore. And with that, we have used infrastructure as code to deploy and destroy a lambda from our AWS account.
This is one of the quickest ways to deploy to your own AWS and define your own infrastructure. It's really terse with architect. The deployment, as you saw, might take, or as you experienced, might take a minute to deploy and might take a second to delete or destroy it as well. But this is still a really quick way to deploy your own infrastructure on AWS. If you want to look into more primitives that Architect gives you, you can come into arc.codes, you can come to their docs, and in the project manifest reference, you can see all the primitives that you get access to.