Syntax Video
SST In Action - Effortless AWS
Transcript
Hey, what's up? This is Scott from Syntax. And since we talked about SST on Syntax today, I thought it would be great to show you it in action in a real practical sense. So, if you didn't catch that episode, go listen to the episode right now. It's out today on the channel and Wes and I actually go through SST, talk about some of the code, and why you might use it. So, if you really need a prepper before watching this, that's a great place to do so. Basically, SST is a way to have infrastructure as code. So that way, you're defining your infrastructure in a single config file that can then deploy where you need to deploy. Now, since this is based on a standard that uses Terraform, we can actually deploy to many different places. You can use all kinds of different services with this. And that means you can deploy things quickly and easily to something like AWS or you can have it automatically update your DNS on
Cloudflare or even ship to deploy to Cloudflare. In fact, if you head into their docs, you can really see all of the different providers and services, 150 plus Palumi, I I think that's how you say it. Correct me if I'm wrong. And Terraform providers. And there is just a big old list of providers here that work with SST. It's really quite incredible.
What I'm going to be doing in this video is we're going to be getting a spelt kit site deployed with SST and then I'm going to show you a little bit about how to work in the SST config files, how we can quickly and easily add services. And you can just see really nice and easily just how easy this is to get going on services like you know AWS stuff that isn't always the most friendly to work in. And the cool thing about most of this is you hardly need to go into the AWS console at all. Now, I will say there is going to be a prerequisite to actually being able to follow along to this. You'll want to head to sst.dev and then you'll want to head into how to AWS account. So, sst.dev docs howto AWS accounts. The reason why is there are some steps here that you need to get going about managing and creating your AWS account, your IM identity center, setting all this stuff
up so that way you can actually quickly and easily deploy to AWS like we will be in this video. So I am already set up with AWS. I'm already logged in with my SSO into uh AWS as well. So that way deployment shouldn't actually be any kind of issue. And the reason why we're not going deep into this is because this could take, you know, 5 10 minutes or so. And I want to make this video more about SST than about AWS because uh while AWS is just one of the possibilities for deployment in this thing, um that is what I'm going to be utilizing. So just keep that in mind.
Now, what's cool about SST is that the getting started documents are really good. So, documentation here, not documents. So, depending on whatever you're working in, you should be able to find something to get started. Like for instance, Nex.js right right here. Uh you have a drizzlebased site, a speltbased site uh using speltkit, a hono based site, a dinobased site. All of these things uh have good examples on how to get going. So let's say you are you just listened to the syntax episode on nux and you're like I'm going to deploy my nux site on SST. You come in here it tells you exactly what to do and in fact there's typically just in a nit script that goes through and does stuff for you. Now the spelt version of this is which is what we're going to be doing here. You'll see that the documentation says that there's two different ways to deploy a spelkit app whether that's serverless or within containers. Now containers is where it's going to run
the full node setup where serverless is going to run a spelt kit site where each of your routes is essentially like a function. And this is really great when it works because it happens automatically. You still get access to things like server side rendering uh but your application can run in a serverless manner. And I found this to be just really nice on SST on AWS easy to get going. And in fact, this is how I I typically deploy my spellkit sites, even on something like Cloudflare, right, using their Cloudflare workers. So, let's go ahead and talk about what we need to do to get started. First, they're going to tell you to create a spelt kit site. I've already done that.
You can go ahead and create a spelt site. The new way to do that is with npx svcre. SV is the new creation utility. It's really nice. You can create a spelt kit site any way you want or you can work with an existing spelt kit site. You can see I have mine right here. It is a barebones site. There is nothing to it. It is made with uh the exact purpose of this video. So, not a whole lot going on. Basic spellkit app. So, when we check this out, it says that we need to run npx SST latest innit. Now, I'm using PNPM. The equivalent of that is PNPX.
You can use npx. You can use anything as long as you know what you're typing in. Um, and we're going to do SST at latest init. Now, this is going to be really nice because you'll get to see just what a cool experience SST is overall because it really allows you to get going without a whole lot of pain. Now, there will be some pain associated with this, but it's almost always going to be your own doing. Uh, anytime I hit snags, it's because it was something that I didn't understand about how either AWS worked or what I was typing and I just needed to look at the docs a little bit more.
So, as long as you're the type of person who can dive into those things or follow along to a video like this, you're not going to have any trouble. And again, you can follow along with the next base site as well and it should work just the same or who knows, a uh next.js if you want. So, PNPX SST at latest init. Okay, we hit that and you can see what this is going to do is it's going to uh detect what kind of application we're going to go on. And so it says spelt kit detected like some kind of robot from shopping mall or something. This will create an SST config and add SST. Continue. Yes. Um love to continue. And I love wizards like this. And this isn't an ad here, but Sentry at century.io has a really great wizard for this, too. Um the the wizard essential the wizard to add
sentry to your spellkit app is gold standard in my opinion where it modifies your code doesn't break anything just gets you all all going and SST is uh very much like that. Uh one thing I even like about the SST wizard is that you don't even have to specify what type of project it is. SST is able to figure that out on its own. Perfect. So, not only did this add, and in fact, we can see what it added in a second, but I can tell you it's going to add the spelt adapter for SST. Now, the reason why you need an adapter for this is so that it works correctly with your serverless functions, those types of things, instead of like maybe a static site or an adapter node. Um, so this is an easy fix. We basically copy this line right here. And if you've worked in spelt at all, you know their adapter patterns, really flexible. Um, we do our config spelt config and we just replace this
adapter auto with adapter SST. Easy, right? Uh, I I I would be I would imagine that any of these other platforms that need the same type of treatment will. Um, so yeah. Okay, so let's see what else it added. In addition to adding the that adapter for us, it also added um an SST dependency.
You might be wondering why it's a dependency and not a dev dependency. SST actually has a runtime component to it if you'd like where you can connect to your resources and use them directly from um SST resources in your code itself. So that's why this is one of your dependencies here. Um in addition to that, you did see that there is the spellkit adapter for uh SST as well. Uh Spellelkit SST. So super cool. That's really all we need to get going. Um, the other thing it gave us was an SST config file. This SST config file looks a little bit something like this. Um, I have no idea why this is giving me a red squiggly right now. It never has before.
So, uh, just one of the mysteries of TypeScript, right? And, uh, it created a SST directory. Now this SST directory just like many other directories like spellkit this thing is generated which means that you can nuke it at any time and it will regenerate. So you can see here that it's given us some default config. Now the default config here is pretty much what we need to get going because as long as I'm logged in to my AWS we should be able to see at least an attempt to get this going. So let's go ahead and so from here we can run PNPM or npm run. Uh in PNPM you just run PNPM I guess run you have to run a script. So uh either way it's it's PNPM npm and then SST deploy. Okay. There is a whole SST dev environment stuff too we'll talk about in just a minute. And you can see it actually gave me an error at first when it added these things. It didn't
run npm installer PNPM install. So, when I ran PNPM SST deploy, it failed. You run PNPM install, you're all good. Oops. Um, I don't know why the the spelt one actually runs npm install. So, I guess I'm just used to that. So, PNPM SST deploy. Now, I can't promise this will be smooth every single time.
Like for instance, right now I ran it and it's telling me that the uh security token that I'm sending with my single sign on isn't actually correct. Now the reason for that is because how I set up my AWS setup when I was setting it up. I have different profiles. I have different uh profiles that are being used. And the profile that I'm currently logged into in AWS is not being used here. Uh, it's actually just trying to use my normal AWS account. It's not trying to use the profile. So, if you're seeing something like this and you know you're logged in, what you need to do here inside of your app config is you need to head into a new property here named providers. And inside of providers, we give this an AWS provider and then we give it a profile. Now, many times what you'll see is you'll see people do something like this.
input.stage is equal to production then use profile for uh prod um or otherwise profile for staging or dev whatever you call this right. Uh this allows you to deploy maybe like a staging or a dev environment on AWS and still have it work. And then you can just specify that with eth with SST deploy stage then the name of the stage right production would give you to the production uh the profile here. Now this needs to be the name of the profile.
Now, I'm going to share with you really quick that I have something deployed with this account and my profile is named after a project that I do called Habit Path. Habit Path is a habit tracker that I'm deploying using SST. Now, since I don't want to go ahead and set up a whole another profile system and stuff, I'm going to just use that habit path production profile. That's the name of the profile that I created and therefore I'm going to use it like this. Now, if you're following the SST docs and you did take a step to do all of the how-to setup with AWS stuff that we talked about uh before this whole thing worked, you know, that's going to explain a lot of the information about profiles. And you can see that in your AWS config, you're using profile, you know, acme dev or acme production. So, the name where I got my profile came from this whole bit. So, I would imagine if you run through this, you have that
profile name all set up. And if not, it's no big deal. Again, you can just follow along and then run through their documentation when you're ready to go. Just want to show you some of this in action. So, with habit path in production, uh this should actually be using the right profile to which I'm signed in on. Now, the my web name here, this is going to be the name of the resource that uh is present anytime you're looking at this thing. So, I might want to give this a name that is not my web here because this right here, the async run section is where you define all of your services within SST.
Now, I'm going to get into this more just a little bit, but new SST. AWS something is a very typical way of how you work within SST. And in this particular case, there is a special spelt kit one and the name of it is just the name of it. So, SST demo. Okay, we can call it that for now just so I don't you know I know what it is when I look at it. So since I should be good to go, let's try PNPMS SST deploy right now.
And you can see it's actually deploying or at least it's saying that it's going to deploy which means that it accepted my profile name. It knows what's going on and we should be good to go here. Whether or not this actually deploys is a different thing. It typically should. You can see it's doing a whole lot of work for us because as it's doing all of this SST is not just um it it's not like Verscell or or something like that where you just give it a build command, it runs a build command and deploys. What SST is actually doing is setting up your whole infrastructure. So beyond just setting up the SST, it's creating an asset policy, a public access block, a uh assets bucket. So it's creating an S3 bucket for you. It's creating all of these resources behind the scenes that your applications will use to function with um all kinds of stuff. Cache policy
um server ro um just you can see just so many different things that it's handling which is one of the reasons why I love SST because I don't want to get in to this stuff on my own. I just straight up don't. I also do believe in infrastructure as code as being a good idea. So, um for me, I really like this approach. I like that I don't have to get into uh AWS land. I like that I can have everything defined in my codebase itself. That worked. Now, it took a little bit long on my end. Now, the reason it took such a long time on my end is my internet right now is being terrible. So, uh if it took a long time on your end, hey, maybe uh that's just how it happens. But now, one thing you'll notice about this success screen is that it gives us a link to sst.dev as well as a link to the site itself. I'm going to open up both of these. Now, this SST.dev link is the SST
developer console. This is where you set up things like autodeploy or check out your logs or make sure that your builds happen or look at error logs, you know, that type of thing, examine why something did or didn't work. And SST console is their paid product. It's uh what keeps SST going. Now, there is an extremely generous free tier. I've never had to pay for SST. That said, if you have a big application, it makes sense to pay for it if you're using it. I I don't think it's predatory by any means.
So, I wouldn't think twice about um paying for this product. Again, not an ad, just how I feel personally. Now, when you first uh get to that sst.dev link, it's going to make you sign up for an account. uh made me sign up for an account. I did. You can see some of the things I'm currently hosting. Uh my habit path app uh just a a zero sync app that I made that's a chat app and then SST uh this spelt site that we just made. So you can see if I click this you can see that we have all of the outputs I have which is the SST demo site as well as all of the different services.
all of the different services as well as anytime that there's been a deploy, it gets added here to the updates. There's issues, if there were problems, um you can even connect it to your AWS account. You can set up logs here. And if we head back to this page by clicking the the main section here for our workspace, um if you click this top where it says SST spelt, it takes you to a different screen. And you might not notice this where there is settings for autodeploy.
This will show you every time your application is autodeployed. And under settings, you can connect it to your GitHub. You give it a repo that you select as being the repo this is tied to. I've already connected my GitHub. You'll have to connect yours. Then you can connect this and get that uh you know npm deployed to production whenever you do a GitHub push to the right branch. Okay. So that's the console.
It's a really neat thing. We're not going to go too in depth on it. There's a a lot here, but for the most part, it's able to just see what's going on in your application, and it is their paid product. Let's go ahead and take a look at our app to see if it in fact deployed. So, I've arrived at the URL here, which is this random selection of characters, and then cloudfront.net. If you've ever seen CloudFront, uh you know that that's their CDN. So, we're getting a CloudFront CDN in this without necessarily even specifying it. So that's great for us. It's something I would have wanted to do anyways. Okay.
So we have our application. It's clearly working. It's on the internet. Now if you wanted to let's say give this a domain. Now I have most of my domains hosted on Cloudflare with that uh if you're hosting a domain on Cloudflare as long as you set a couple of enviables.
And I I don't I'm not going to actually give you my ENV variables here, but there's a couple of ENV variables you need to get. You need to get the Cloudflare API token and the Cloudflare default account ID. If you have these two, I'm just going to give it a a non-real value. If you have these two in your env file, whenever you give a domain inside of your SST config to anything, it's actually going to go into Cloudflare and update your DNS records for you. You don't have to do anything and it will get your domain on online.
It's really neat. And and to do that um obviously this will break deployment because I'm not giving you my real Cloudflare um stuff here but you would come in here inside of this where you define your service and you give it some additional options. So we comma and then you have your options and inside of these options there is a domain property. Inside of the domain property you can give it a name. So your domain name. So tool.sk ski, which is a real domain I have, but I'm not going to actually use it. And then you give it a DNS value, which is where you can configure the service for your DNS. So, if I was going to be using a Cloudflare DNS, in fact, sorry, this is not an object. This is just a a property value here, you use SST.cloudflare uh DNS like this. And that's it. Uh, sorry, not a you just have this like this. And as long as you own that domain, it's connected to the account of the the API credentials you gave it.
When you go to click deploy, it's going to provision and get your DNS set up for you. It's really pretty amazing. So, if that is something you are interested in, again, follow along at the SST documentation here. You just need to actually, you know, one thing that I do is I just kind of come in here and always I always look just at these uh the docs. The docs are really good. The AI assistant's actually really good. I wonder if I type in Cloudflare if it's gonna show me what I want here.
Um, it's funny that I'm uh failing at this, but the easiest way to see this in action is to um go to the how-to section and then custom domains and it will show you you give it a domain or you give it a domain name and then DNS. If your domain is hosted at AWS, you can do it this way. Um, again, if your domains are hosted on Versel, you know, you do it this way. Here's what I was talking about with the Cloudflare. You add Cloudflare here. You give it these credentials in your envi. If you need a domain here and you don't want to set up the DNS on your own, you can do it this way. Now, another one might be if your domains are hosted who knows where. Uh, Google Domains got bought and now they're on Squarespace. I've never even logged in on my Squarespace to check on those.
They just renew somehow. Uh, if you did that, you can follow these manual directions and get your domains going. Okay, so let's talk about SSTDEV before we add another service. Now, I know everybody is really used to doing npm, rundev, pnpmdev, all that stuff, but uh SST has a built-in dev environment that actually runs your functions uh as functions. So, that way the development environment mimics your production environment because like what you're running uh your code a certain way with serverless functions, you kind of want you kind of want to know what you're up against when you're you're working like that. So if we do pnpm sstde dev, this will just kind of inherently pick up the dev command in your script and it's going to get you going in a dev environment. And which is really neat. It gives you a local console as well. It tells you the stage.
It tells you the app. It deploys your things like you typically might expect it to do like it does in production. And at the end of this uh like I said, my internet's being really slow right now. At the end of this, you just get a normal dev URL and you can work in this application just like you typically would in a development environment. Now, the reason you'd want to do this beyond that is if you are using different services. So, like if I'm using an S3 bucket and I want to test that or I'm using uh RDS, I'm using any of these uh AWS services, a database, whatever. Um, many times you want to be able to pass those resources into the runtime of your application. And to do that, you would need to then run SST uh dev, otherwise that stuff's not going to work correctly for you. So, it might feel a little heavy-handed for SST to take over your dev environment. And I promise it's not this slow usually. I don't know what's
going on with my internet, but it's it's not that uh SST will, you know, it it does seem scary that it takes over your dev environment, but it does so for a good reason, especially if your application relies on various services and how they're connected and you want it to just all seamlessly work. Okay, you can see here that uh my internet finally kicked back in. It has deployed at least to development mode. You can see that we have our console as well as the dev of our uh actual application.
Now the more services you use, the more things that will show up in the sidebar. So if you have a server like I had a zero sync site, the zero sync server showed up in here. Uh because that's a whole process. Uh I had a replication manager service that's showing up in here. Um, all these things that are running are going to show up as different services over here. You can use your keyboard to do any of this stuff. There's keyboard. I'm a a mouse clicking guy. I know that drives people nuts sometimes. But you can see here that we are given our domain. And from this point forward, this will function exactly like our typical dev environment. In fact, if we head to our route, we can say welcome to SST. It's not any slower than what you're used to.
Okay. It's just a nice little thing that you can have in addition to uh all of the deployment. You get access to a development environment that again utilizes the services in your infrastructure. So, I'm going to stop that with command C like normal. Head back into our SST. Okay, cool. So, inside of our async run here is where you're going to define most of your stuff. And I can show you just a little bit of a more intricate SST config that I've done. And you're going to see because this is a TypeScript file, uh you can run JavaScript in here. Believe it or not, I'm even importing read file sync in here for some stuff I got to do.
So, uh there's console specific uh properties inside of our config because I wanted to specify a node version for the autodeploy. Okay. Uh, so let's let's minimize that. Inside of my app, I gave it a name. I, you know, I give it my removal, my protect, my home is AWS providers, and I did exactly what I was telling you before, like what is the stage? You can tell I did this right because I misspelled habit path in the dev environment and just didn't care. I I I'm not going to deal with it. It's fine. I don't I don't care about that.
Um, I did specify Cloudflare as a provider command because I needed to run some commands. Um, I did specify the region and then you get into your run business. Now, within your run business, again, this is just a load schema function that loads up the schema for zero sync. Here's a uh version number for zero that I wanted to use in pin.
And none of this stuff is super important. What gets important is when we get into the definition of services. So, for instance, I created a VPC, a virtual private cloud using SST AWS.VPC. Okay, easy enough. Uh, Bastion allows me to tunnel into it if I need to, which you may. Um, there's a lot of intricacies here that we're not going to cover in this video. I just want to show you getting going with SST and a little bit about it beyond what we did in the podcast. And then we have an ECS cluster where I'm then able to utilize this cluster. I'm attaching it to my VPC and I am saying here's my cluster and then I have a database which is using sst.awws.postgress. I wanted a database.
I did it with this. Um I'm then once again passing in my VPC. I'm giving it a name. Um I have some special things about logical replication that I need for zero. Typically you won't need that stuff. And then I'm able to specify, which I'm not going to show you, a dev database address because in SST, if you're working with a database like this, it might be just straight up easier to to actually connect to a local DB instead. So I gave it my local dev DB credentials in here. That way when I run SSTDEV, it utilizes that. I can build my connection string by actually utilizing the the variable here database.name username.p password.host and then using this interpolate uh string template literal to uh go ahead and create the db connection string which I'm then able to pass into things. Now you can also set secrets which you set via the command line. Those secrets can be then used
inside of your config uh in various ways to pass into your applications or to transform or whatever. Um these are these are basically env variables that you can set from the command line. Now this is using some outofdate syntax but it is uh just loading up one of my uh containers. So it is using a service on my cluster. I'm able to set up an email service as well. Now if you are setting up an AWS email service, you will need to go into uh their console and mess with some stuff, get approved, send some test emails, yada yada yada, that type of thing. And then you can see I am in fact using speltkit as well. Now one thing you may notice here is that we're using a link property occasionally. Link allows you to link two separate resources together. So in just one second here we're going to do exactly that. Let's get rid of this one and let's head back to our SST dev here because in these docs and we're going to follow along with some docs that they
actually have on their own. If we do the getting started and we do spelt, you'll see that if we come down here, it tells you to add an S3 bucket. I think this is a good demo and so I'm going to utilize this demo as well. So if we want to add a second service to our current one, you can create a const bucket um is equal to new sst.awwsbucket AWS.bucket and then you give it a name SST demo bucket. Really creative name here. Um, comma. And then we have some options. Now, I'm going to make this access uh public just because. Now, if you weren't going to be utilizing this resource and linking it to something else, there's no reason why you couldn't just have it like this.
It's going to create that bucket. But since we want to be able to link the bucket to our SST site here, we'll want to go ahead and create a variable for it for then inside of our options, we can utilize the link property and pass in our bucket, which means that we can now access this bucket in runtime code via SST.resource inside of our spelt kit application. And that's really pretty special because it allows you to do this with the connection of your resources in a way that makes your development environment really similar and with the same code as your production environment. I'm not having to have several different ENV files. I'm not having to do a lot of checks if this then that then show this thing or use this code. I'm able to just use sst.resource and get access to that information. And in fact, let's go ahead and do that with a very simple image upload form that again they're providing us to us in their docs. I think this is a worthwhile demo. So, we're going to
add a new script here. Um, I'm going to do lang ts. Why not, right? I guess that's not living on the wild side. Uh, I'm going to I'm going to one have to translate this to spelt 5 code. This is spelt 4 code. If you don't care about spelt, fast forward until we're getting this going and I'm showing you the AWS stuff. We're gonna say const data is equal to dollar sign props like this. And then we're going to say const. And check this out. I'm going to actually name this onsubmit because you'll see why in just a little bit. I'm going to name this onsubmit is equal to an async function with e um again this is fault five code and so it'll make sense in a second where we do need to call e prevent default and reason being is that spelt 5
does no longer has this pipe prevent default which is sad to me personally. Um, out of all the changes in spelt 5, I think that might be one I dislike. Uh, just because I I liked it. And so from here, we're going to say const form data is equal to new form data. And we're going to get E.target. Okay. E.target. Then we're going to say const file is equal to form data.get and then file.
Okay. So nice and easy here. Um this is giving us our e.target. Now from here we're going to say const image is equal to await fetch data dot you oh my god typing URL and we're going to pass in body is equal to the file itself. The method is going to be a put and the headers are going to be equal to uh content type file.type.
Okay, whether that's an image or not. Content disposition. I regret doing TypeScript because now I'm going to have to deal with these types. Attachment file name is equal to and then string interpolate this file.name. Okay. Now from here we can go ahead and create our form. Now our form we're going to keep it pretty simple.
The form action is not going to be anything. But what we can do with this new spelt 5 syntax is just say onsubmit and that's it. We don't have to specify anything else. Uh that's really super nice. From here we can have an input and the type is going to be file. Um the name is going to be file and we're going to accept an image for slashpng or an image JPEG. So just so that the UI understands what we're accepting here. And then lastly, we'll have a button which is just upload and it's going to be a type of submit. Okay, sorry that was long- winded, but the reason why we're showing you this is because this data URL is going to come in from our server side loader. Now, in spelt kit or any way you
want to do this operation on the server side, the way you do it in spelt is by having a page.server.ts. Okay, this is going to be your load function. What this is going to do is head to AWS, use our SST resource, and then pass that signed URL into the UI of the application via the data props.
Okay, so now that we have this resource here, let's actually write the bit of code that allows you to connect things. So export async function load is going to be just a simple loading function. And if you've ever done this in spellkit, uh you'll know what to do here. But if you haven't, uh this is a good opportunity to see how this works.
Either way, all we're doing is getting a signed URL from our SST config on the server side. So we can say const command is equal to new put object command. This is an S3 thing that you're going to be importing. In fact, put object command is coming directly from um AWS client SS3. And and in fact, let's just go ahead. I'm going to copy these straight here so you can see it without it. I mean, it will have red underlines here and there, but we're going to be bringing in S3 client and put object command from client SS3.
We're going to be bringing in get signed URL from S3 request pre-signer. And we're going to be bringing in resource from SST. Now, resource is the thing that I've been talking about, and that's what's most important, I think, in this section of this video. So, we're going to be calling this uh new command. Actually, you know, while we're here, um let's go ahead and install these things.
So, any means that you typically use to install things, just go ahead and do that. New PNPM add S3 client. Um I'm sure there's a faster way of doing this, so don't roast me. Um, and then we already have SS uh S ST. So, bring in these two and it should get rid of that concern there.
Okay. Restart language server, restart TypeScript server. There we go. Okay. So, let's head back to the demo that we're following. And within that demo, it says to first give your object command a capital capital K key, which is crypto random UUID.
Okay. And then also what the bucket is. So bucket and then this is where the SST stuff gets interesting because inside of our application in our runtime code, we can finally get access to our resource. whatever the bucket's name was. So if we go to our SST config, you remember I named it something interesting. It was SST demo bucket. So I grabbed that bucket name. So resource SST demo bucket name.
Uh now I haven't deployed since I added this bucket. So it's going to say that it doesn't exist for right now. But that will fix itself. And then we can click save. Now this resource dot the resource name is a flow that you will use for defining database credentials uh for linking buckets or even URLs if you create a a private URL or something.
There's a lot of interesting things you can do just by grabbing this resource. But I I do understand if you are skittish about bringing SST into your actual code because that is brings you into some sort of lock in, right? And in that case, I do have something for you. At any given point inside of any of your things here, we can specify an environment like this. And this is going to be where you put your environment variables. So in the situation where you didn't want to actually use that resource name here, you could always specify bucket name as equal to and then you can use the dollar sign interpolate bucket.name exactly like what I did here where I was able to grab the database name. If you were to just pass in
bucket.name here, this would not work. You do need to use this interpolate to get the actual value. Okay, so you could utilize this and then that would become access as process.env.bucket name like you're typical uh typically used to if you don't want to use the resource thing. So that works as well. Okay, so we have this here SST demo bucket. All that all that is good and we can then const url is equal to await get signed url new s3 client and then we just pass in the command forgot one pen there we go wrong pns and then we can simply return this signed URL as data like this now this is going to solve a couple of things for us if we have this like this you can pause the video here and copy this code. But granted, it's the exact same thing that's on the SST dev docs. You can copy it from there, too. Um, what that does
is it now gives us this data URL, which the next time we run spelt sync, this will fix this TypeScript error. Let's go ahead and see this in action. In fact, I'm uh after this is all said and done, I'm simply going to just console log image right here because that should be able to tell us if this uploaded or not successfully. So, let's head back and let's once again add PNPM SSTD dev. I had stopped that to install some things.
Uh, PNPMS SSTDEV this time is not only going to just get us up and running with our current config, but it's also, as you can see here, creating our bucket. Um, so anytime you add things, you will see created. Anytime you remove things, it will say destroyed or I think destroyed or deleted. There it is, deleted. So, um, it deletes and creates things, updates things as needed. Okay, so here we are. We're up and running.
You can see much faster that time. My, uh, ISP must have gotten it [ __ ] together and we can come back here. So, the first thing I'm going to do is going to open up my console here and get rid of this what's new business and just have it nice and big. And then I'm going to click choose file and choose a file. I've I've got my image here. It's a photo of Chad Whitaker from Syntax. Chad is a new member to the Syntax team. I'm going to click upload here. And you can see we've gotten a response. This time it has given us a URL. Now that URL again is going to be public because we specified that we wanted this bucket to be public. So let's go ahead and check out this URL and see if this thing uploaded. So now I'm going to have the URL in here without the query params.
And I'm going to hit enter. And you can see it downloaded the image, which means that this is coming directly from an AWS bucket. we've got that uh actual URL for what this thing is and that means we could work with this as a real asset in our application. I mean, you've essentially just built an image uploader that now you can utilize these images.
And in fact, if we wanted to just drop that image directly into our codebase for some reason, hardcoded in here, let's just get rid of one all these extra quotes. Oh my word. Let's get rid of all of these extra query parames. We don't want them. And let's get rid of alt text for now because we're just trying to get this to show up. Just the URL. There we go. Just the URL for the image itself. And there's Chad. Hey, what's up, Chad? Uh, so we got it working here. So, we've built a nice little image uploader. And this is a nice little project so that way you can see everything that SST can do. Now, I've shown you how to link resources.
I've shown you environment variables. I've shown you domains. There's a lot else. SST is a deep well. I could be talking on this stuff for days. Uh there's so many cool things you can do with SST. But as you've seen by me following some of the documentation with you here, the docs are really good. Uh they help you out with a lot of stuff.
And the only hiccup you might have is, you know, spelt for code. That's not a huge hiccup, but if you use any of these services or any of these things, the documentation is there to help you. The AI tool is decent. Just don't trust everything it says. Go and look it up in the actual docs. Um, follow some examples that exist. There's a lot of great stuff in here and you can get really complex with SST having a ton of different services. So, let me know what you thought of this. Was it tough to get AWS running? Did you uh get it running?
Did you choose to use Cloudflare? Uh, what are you what are you deploying on SST? Are you already using it? Do you think this thing is viable? Me personally, I like SST because I don't have to host my things on an AWS rapper. You know, there's a lot of AWS rappers out there. I don't have to host them on an AWS rapper. I can host them on actual AWS without having to pay the middleman, right? Uh, nice little bit. And if I can do Nex.js there or spelt kit site there or any of these things, I don't have to host on the middleman. Okay, so check it out. sst.dev dev. A really neat project and something that I'm super interested.
If you want to learn a little bit more about this, check out the syntax episode on SST. It's really great. Vice versa, if you came from the syntax episode and wanted to learn more here, welcome. Let me know if there's anything else you'd like to see or issues that you're having with SST. As always, this is Scott with Syntax. See you in the next one.
Quote it with credit and a link. Quoting Syntax