AWS SDK with Go

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone my name is Sherice and welcome to code with Sherice in this tutorial we'll be going over how to use the AWS SDK with go sdks allow us to use programming languages like go to interact with AWS services like S3 Dynamo DB and many more this makes the SDK a very useful tool and skill to have to automate AWS actions being able to automate AWS actions is a key skill for any job that involves working with the cloud so if you want to learn more about automating task in the cloud then continue watching okay so our first step here is going to be to create a new go package by using the go mod command so I'll run that now okay this now gives us our go dood file um now we'll just create a main.go file all right so we have an empty main.go file file which we will now add our SDK code to it's going to go very fast but I'll go over what each line means after I've completed the file okay okay now that I have finished writing the code I'm just going to run go mod tidy to um download these packages looks like we have an error here so let's just look oh I have a issue right here this should be for uh go and I'll run that again now that we've downloaded all the packages that we need all of the red squiggly lines have disappeared so let's now go over what this file actually does so the first couple lines are pretty stereotypical for go programs we have a package declaration here and then we're importing some important packages and uh to really have a understanding of what these packages do I'll just skip to the main function um to show how they're actually used okay so the first thing we do is we're going to use the config package to configure the AWS environment that will be running our SDK in so in this case I'm just loading the default default um configuration so this lad default config will basically search for different kinds of credentials in the following order first it will find the environment variables and if those environment variables don't exist it will look for credentials in the AWS credentials file and if that doesn't exist then it will go to the AWS config file and then lastly if that one doesn't exist it will look at the instance profile that's attached to an ec2 instance if you're SDK code is running on an an ec2 instance so in this case I'm running it on my own machine so it will so it's able to find the credentials from the environment variables next um it just checks for errors and assuming that that there are no errors it's it goes to the next part which is to set up the S3 client so the client is basically how you interact with different services in this case we want to interact with the S3 service so we need to get the the um client for S3 and this is the syntax that you'll use next we're going to perform some actions on the S3 service and the action we want to perform is to list the objects in a specific bucket so we'll see we're using the client to list objects using the version two of the go SDK there are two versions but for this tutorial I've stuck with version two cuz that's the latest one and uh next it just takes a context um in this case is going to be empty and we are going to also pass the parameters needed so in this case it needs the name of the bucket and that bucket is going to be my bucket F4 B7 so this is a bucket that exists in my account but in your case you're going to be taking another bucket that exists in your account and then add the name of that bucket here and here we're using that AWS package so you can see we have the AWS package here we are using it to convert it to a format that the go SDK can use so um once that's done if there's any errors it will log them otherwise it moves on to the last part which is the most interesting so lastly we're just going to um Loop over the results of that call so it gives us an output and we're just going to Loop over the results and we're just going to print the the the object key as well as the object size so it's a very uh simple program but gives you a very good understanding of how to use the go SDK all right so now let's see this in action so we've already downloaded the required go packages so the next thing we'll do is just run the go build command to just make sure we have no errors okay we have no errors here and we've also created a main file which we can just excute by running dot slash main okay so in my case everything works as expected because I've already set up my AWS credentials but if you don't have your credentials set up here then this won't work and you'll get an error but in my case I've set up the credentials so we're able to list all of the the objects in this bucket as well as their sizes I hope this gives you a really simple introduction to using the AWS SDK for go thank you for watching if you enjoy this video please hit like And subscribe if you have any questions leave a comment below and I'll get back to you as soon as possible see you next week
Info
Channel: Code with Cherise
Views: 525
Rating: undefined out of 5
Keywords:
Id: mE5-99qcBFs
Channel Id: undefined
Length: 6min 6sec (366 seconds)
Published: Tue Jan 09 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.