Overview
Join Knox Hutchinson as he demonstrates how to use Cloud9 as a method to develop and deploy AWS solutions.
Recommended Experience
- 1 to 2 years of devops or cloud experience
Related Job Functions
- Cloud Engineer
- Solutions Architect
- DevOps Engineer
Knox brings a wealth of data analysis and visualization experience to CBT Nuggets. Knox started off as a CBT Nuggets learner, became a mentor in our Learner Community, and is now a trainer. Having benefited from the CBT Nuggets Learning Experience firsthand, Knox creates training that connects with learners.
Introducing Development in the Cloud9 IDE
Let's explore AWS's native, web-based IDE.
Understand Cloud9 Features
Let's see why someone might choose to work with the Cloud9 IDE.
Knowledge Check
What is needed to open your Cloud9 IDE? (Choose two)
- AInternet Connection
- BWeb Browser
- CVS Code
- DPython
- EDocker
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Prep Users and Roles
Let's get our users and roles straightened out for working with Cloud9.
Knowledge Check
Which role has the rights to create an environment for the current user only?
- AAWSCloud9User
- BAWSCloud9Environment
- CAWSCloud9Administrator
- DAWSCloud9SSMInstance
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Create a Cloud9 Environment
Let's bring a Cloud9 Environment to life.
Knowledge Check
You can only deploy Cloud9 EC2 instances with a max of 16GB of RAM. True or false?
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Adjust User Permissions
We now need to circle back and make sure our users have all the rights they need to work with SAM templates.
Knowledge Check
Which of the following is NOT a resource that a user would need access to in a SAM deployment?
- AEC2
- BS3
- CLambda
- DAPI Gateway
- EIAM
- FCloudformation
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Create and Deploy a SAM Template
Let's now look at how to scaffold and deploy a full SAM solution.
Knowledge Check
Which command will deploy your application with prompted parameters?
- Asam deploy --guided
- Bsam build --use-container
- Csam deploy
- Dsam ship --guided
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Test, Debug, and Fix Any Issues
Let's now explore how we can use our Lambda function!
Knowledge Check
The default proxy configuration on API Gateways will alter the payload provided to the backend lambda function. True or false?
Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.
Conclusion
I hope this has been informative for you and I would like to thank you for consuming.
View Transcript
Introducing Development in the Cloud9 IDE
0:06Welcome to the content on using the Cloud9 IDE baked
0:10straight in to AWS console.
0:13What is this all about?
0:14Well, what's the benefit of the cloud in the first place.
0:16Really think about it here, stretch your mind.
0:18It's the fact that the cloud is always on and always reliable,
0:21and you can get to it anywhere in the world,
0:24as long as you have a web browser.
0:25It's not necessarily the case with our IDEs
0:28that we like to use and prefer.
0:29I prefer VS Code personally.
0:31Some people who work with Python use PyCharm and so
0:34on and so on and so on.
0:35The idea here is that what if we just
0:38had our IDE in a web browser and wherever
0:41we could get to a web browser we could then get to our code.
0:44All of our code, the sessions that we're working on,
0:47all of our privileges, all of it is
0:49attached to that exact session that we can work with.
0:53So in this set of videos, we are going
0:55to explore the capabilities and features of the Cloud9 IDE.
0:59Even rolling up our sleeves and seeing it
1:00in action with the basic Lambda SAM deployment.
1:03Get ready because this is going to be a lot of fun.
1:06Let's go.
Understand Cloud9 Features
0:00[AUDIO LOGO]
0:06So what do you need to know about Cloud9 before you use it?
0:09That's what we're going to explore in this video.
0:11This is the built-in IDE that comes with the AWS console.
0:16You can do all of your development work
0:18with all of the necessary requirements
0:21like the AWS CLI, the SAM CLI.
0:24All of that is baked in to the IDE by default.
0:27At the end of the day, it makes working with AWS resources
0:30a heck of a lot easier.
0:32So in this video, we're going to explore some of the features
0:34and capabilities of Cloud9.
0:36Let's go.
0:37So Cloud9, what's it all about?
0:39Seems cool, but we need to dig a little deeper
0:42and we need to understand what it is that Cloud9 really
0:45brings to the table.
0:46I'm going to drag my browser here onto the screen
0:48because pretty much everything we're doing here
0:50in this particular set of videos can
0:52be done entirely browser-based.
0:54What I'm going to search for is AWS developer.
0:57Just search for AWS developer.
0:59And if we scroll down just a hair--
1:01I'm looking for AWS Developer Center.
1:04I know, certified developer is, well, why we're here,
1:07but we're going to jump to the AWS US Developer Center.
1:10And this is going to be your happy place.
1:13So if you are serious about becoming an AWS developer
1:17and you don't know where to start
1:18with one of their products, I'm going
1:20to tell you right here is where you want to start looking
1:23through one of their products.
1:25They have a lot of cool events, SDK information.
1:29And if we scroll down a hair, you'll
1:30find more about their tools and resources
1:33or you can discover what is possible.
1:37What I'd encourage you to do for this set of videos
1:40is under the More Resources, you'll
1:41actually see the exhaustive list of tools right there.
1:45Give Tools a click, it fires up all of your developer tools.
1:49You can pick your programming language of choice right here.
1:52And the big thing that we see is we've got getting
1:55started guides, how to build applications, and--
1:59oop, there it is.
2:00That's why we're here.
2:01Build on AWS with an IDE.
2:04IDEs are awesome.
2:06I mean, I've been working with them
2:07for years and years and years.
2:09VS code is now my preferred IDE, especially
2:13with all the modern extensions that are built into it.
2:16But for newcomers who are getting started with AWS,
2:20it makes a lot of sense to use the IDE that is baked straight
2:25into your web browser.
2:26All you have to do is log in and--
2:29well, if you have enough permissions-- launch the IDE.
2:33That will then have the entire state
2:35in session of all of the things that you want to build.
2:38It'll have all of that in one spot.
2:41And it can even work with Git repositories.
2:44So you'll imagine here-- you're going
2:46to see it in just a second.
2:47But you'll imagine here kind of a file browser, a directory
2:50browser here, a terminal down at the bottom, and then
2:54the actual code view at the top or the actual files
2:57that you're editing.
2:58So it's not unlike any other IDE that you've ever worked with,
3:01except it's not locally on your computer.
3:05This is being hosted on a virtual machine in the cloud.
3:10And the state that you're currently working with--
3:13like if I'm working on code and then I close my browser
3:17and walk away, and take a lunch break for two hours.
3:21When I come back and go back to that website
3:24where the actual IDE is, pops right back up where I was.
3:28Now it still makes a whole lot of sense
3:30to use Git repositories.
3:32That way we could persist our code changes
3:36after we've want to actually check in some code.
3:40And nine times out of 10, that's going
3:42to be a major part of your CI/CD and your DevOps pipeline
3:46anyways, right?
3:47So that's why having Git baked into this
3:49is already a big deal.
3:50But it also has the AWS CLI.
3:54It has the SAM CLI.
3:57And it has popular SDKs that you want to work with.
4:01It even has Docker installed on it.
4:04I'll tell you right now, one of the more popular things
4:06that I've seen this IDE used for is to build containers.
4:11And then ship those containers directly
4:13from the IDE to the service that they're targeting.
4:16So that may be the Elastic Container services
4:18or it might be something like a Lambda function
4:21that runs as a container.
4:22The point is, is all of this now has integration in mind here.
4:28I think that's the biggest thing.
4:29So when I launch as user A right here,
4:33my user A, if they already have permissions
4:36to interact with things like Lambda functions
4:39or with API gateways, when I type commands down
4:43here in the terminal to ship code to those areas,
4:46it'll automatically be able to use
4:48user A's credentials baked directly into the token
4:51that the browser is holding.
4:53see, it's a huge win because now there's
4:55less friction for getting started.
4:59Look, just being totally honest here,
5:01you're like getting started with AWS,
5:03it's not the easiest thing on the planet.
5:05So any tools that can help you get up to speed quicker
5:09are very much welcome.
5:11And having dependencies, having command line,
5:14having containerisms, having all of that handled for you
5:18is a huge win.
5:19Now there are some factors that you probably
5:22want to know about Cloud9 before you get started.
5:27It does support a huge number of programming languages,
5:30but not every single runtime is on the latest and greatest.
5:34For instance, as of the time of this recording,
5:37Python is now on version 3.11.
5:40However, Cloud9 and even many of the different resources in AWS
5:45do not natively support Python version 3.11.
5:49You can get around it by running containers, of course,
5:52but still that's neither here nor there.
5:54So you'll want to double check, first of all,
5:56if you are developing in JavaScript
5:58and you need to use node or NPM packages,
6:01you want to check the versioning items that you run into there.
6:03Same with, really, any programming language
6:05like Python, like I just highlighted just now.
6:10The other things that I want you to know about
6:12are that this runs on top of an EC2 instance.
6:16The actual IDE itself runs on top of an EC2 instance.
6:20Whenever you want to test things out,
6:22whenever you want to, say, test the code out by running it,
6:26it can deploy an EC2 instance alongside it,
6:31ship the code to that EC2 instance,
6:34test it out, and then return the results back.
6:36And then tear down this EC2 instance when it's done.
6:39That is something that can be done.
6:41It makes sense if you're in a very large enterprise,
6:45like a huge business where they have a lot of policies
6:48in place, it makes sense that you
6:50may have your sysadmin deploy these instances in advance.
6:55That way whenever your user needs
6:58to connect to this EC2 instance and this EC2 instance needs
7:02to connect into that EC2 instance, all you have to do
7:05is provide it with SSH info to do that.
7:07You'll see when we actually get to the deployment of Cloud9
7:11itself, there are two options for how you as a user
7:14connect in the first place.
7:15And we're going to choose SSH to handle that.
7:17But just know that you do have the option
7:19to pre-provision these resources and then provide
7:24SSH information for how they will all speak together.
7:27Speaking of that sysadmin, there is
7:29one particularly interesting thing
7:31that you should be aware about.
7:33And that's the as of the time of this recording,
7:35Cloud9 is not automatically maintained by AWS.
7:41What am I talking about there?
7:43Well, there's a couple different operating systems
7:46that you get to pick from to run on your EC2 instance.
7:49When I say they're not automatically maintained,
7:51I'm saying that AWS is not going to handle
7:54the patching of those operating systems
7:57or the runtime environments that run on top of that.
8:00That'll be on you to handle it.
8:01But if you already are in an environment where sysadmins
8:05are deploying the EC2 instances for you,
8:07that just becomes part of their lifecycle, their upgrade cycle
8:10at that point.
8:11So not the end of the world, but something that you do
8:14need to be aware of.
8:15Especially if you do find out about security items
8:18or patches that need to take place, there you go.
8:22Now I can't stress this enough, this really is a full IDE.
8:25Outside of the fact that you can do things
8:27like you're seeing here with no split screen
8:30editors on the screen, you can configure runtime environments
8:33and de-buggers.
8:34You can integrate different tools
8:36for serverless environments.
8:40If we keep scrolling down, you'll see all sorts of things
8:43here, like the built-in terminal.
8:44And I think this was one of the cooler options that I've seen.
8:48When you create your Cloud9 environment,
8:51you can actually share a link to that environment,
8:53your own personal environment, to other people
8:57in your organization.
8:59And that will enable collaborative chat and code
9:03editing right there on the screen.
9:05Beyond that, like I said, CICD can be baked into it.
9:08Pretty cool.
9:09And Get is baked into it, so we do see things like File
9:12Revision History and-- of course, everybody's favorite--
9:15Themes.
9:15Got to have those themes, right?
9:17So you see, there's a lot of things that Cloud9 can do.
9:20And in the next few videos, we're
9:21going to walk through the basics of getting your environment
9:24ready for Cloud9.
9:25And then actually standing it up and publishing some code
9:29with it.
9:29I hope this has been informative for you,
9:31and I'd like to thank you for viewing.
Prep Users and Roles
0:00[AUDIO LOGO]
0:06Now like most things, in AWS, it's
0:08not as easy as just click on the resource and it's deployed.
0:11We have to have users, permissions, roles, groups,
0:15all of that squared away up front before we get going.
0:19So in this video, we're going to introduce and kind of reinforce
0:22the concept of how the best practices of creating groups,
0:26users, and roles should work.
0:27This isn't going to be the exhaustive list of all
0:30of the roles that we need.
0:31You're going to see that in an upcoming video
0:33where we have to circle back and add some additional roles
0:37into the mix.
0:37So without further ado, let's start
0:39by standing up a test group, user, and some permissions
0:42to get them at least in the door to working with CloudNine.
0:46Let's go.
0:48All right, it is time to have some fun.
0:50I am going to get signed into the console as my root user.
0:54Let me see here.
0:55Oh, I'm already signed in as my user.
0:57Just to be safe, I'm going to sign out,
0:59make absolutely sure I'm signed in as my root user.
1:01Sometimes this happens.
1:03So I'm going to sign in as my root user.
1:04Thank you LastPass and multifactor authentication
1:07for keeping me nice and safe.
1:08I'll go ahead and sign in.
1:10Let me get that MFA code and we'll circle back to it when
1:12I'm--
1:13All right, so now we are getting signed in.
1:16Now, like everything else that's in the AWS environment,
1:21you can deploy users or resources all day
1:24long but none of those things have roles, or access,
1:28or privileges by default. So what I'm thinking here
1:31is I may have a group of devs and those group of devs
1:35are going to be working in CloudNine.
1:39In particular, they're going to be working with and deploying
1:43Sam models.
1:45In this case, Sam models could mean a few things
1:48but really, what I'm focused in on is deploying a Lambda
1:51function and an API gateway.
1:55The API gateway serves as basically on the edge.
1:59Here's the internet out here.
2:00There is the internet, that's going to be the cloud.
2:02The API gateway sits right here kind of on the edge of it
2:06and it serves as the first point of defense, if you will.
2:09It's going to process the payload that comes in
2:12as well as read the headers, handle authentication
2:15if that's something that we need to do,
2:17and then it sends it to the backend which is where
2:20the Lambda function lives.
2:21In fact, you know what I probably should do,
2:23I should probably just write this as a Lambda.
2:25So there we go.
2:27Then the Lambda function runs its function.
2:30It returns a response back to the API gateway
2:33who processes the response and sends it out that way.
2:36This is what the serverless application model is all about.
2:42But in order to do all of these things,
2:44a user needs the privileges to deploy their own CloudNine
2:48environment they need the privileges to work with Lambda
2:53in API gateways, they even need privileges to work
2:57with CloudFormation and S3.
3:01If you don't have any of these things stood up already,
3:04if this is the first resource you've ever deployed in AWS,
3:07there's a whole lot of privileges that need
3:09to get taken care of first.
3:11So right now, we're starting off on the very, very basics where
3:16we're just going to get the devs access to CloudNine so
3:20that they can create their cloud nine IDE environment
3:23and poke around.
3:25Then, they won't be able to do much at this point,
3:28except for you start poking around maybe
3:29clone a repository, start editing some code,
3:32but they can't ship it.
3:33That's why in an upcoming video, we will circle back and then
3:38add the additional roles and privileges via the policies
3:42that they need for Lambda, API gateways, CloudFormation,
3:45and S3, OK?
3:46All right, so there.
3:47Now we've got that objective under our head.
3:50I'm going to jump to my IAM section.
3:51I've already got it pinned right here, recently visited.
3:54You can, of course search for IAM, right here.
3:56It's the first thing that comes up
3:58or if you really want to, can open up services,
4:00scroll all the way to the bottom where you see security,
4:02identity, and compliance, and then jump into IAM right there.
4:06You can also hit this little star right there on the spot
4:09if you haven't done this yet and now it's like a little bookmark
4:12right there on the screen.
4:13Pretty cool, right?
4:14So I'm going to jump into IAM and let's go, there it goes.
4:18It spins up.
4:20Now, what am I going to do?
4:21First things first, the best practices
4:23here are to create a group.
4:25I am going to create a group called devs, very
4:28straightforward name, right?
4:29Let's go devs, like so.
4:31I'm not going to add any users into this group
4:33right now, see how that's optional,
4:35but I am going to give it the CloudNine policies.
4:39I'm going to search for CloudNine right here.
4:41And what do they need?
4:42They need CloudNine user.
4:45Now what is this all about?
4:46One of these different roles all about?
4:48First of all, CloudNine user is someone
4:50who is allowed to create their own IDE CloudNine environment.
4:58A CloudNine administrator is someone
5:00who can see all CloudNine IDE environments,
5:03tear them up, delete them down, add permissions, and so on.
5:06The environment member is someone
5:09who is allowed to open an already existing IDE
5:14but they can't create their own.
5:17The SME instance profile right here
5:20is for if they specifically want to connect
5:23in to the CloudNine environment using the SME AWS service.
5:30So instead of connecting through SSH,
5:32we're actually allowing AWS to handle these secure connection
5:36on the back end and then present the console to us
5:39through the browser.
5:39Now, that's still going to be the same exact experience
5:43you're going to get either way.
5:44It's just oftentimes it's often thought
5:47that a AWS makes it a little bit more secure when you use SSM.
5:50Not entirely mandatory unless you have
5:53a company policy that says so.
5:54In my demo case, I'm going to keep this
5:56as frictionless as possible.
5:58And use the cloud nine user to create the group.
6:00So my group is going to be named devs and the CloudNine, AWS
6:05CloudNine user is the policy that I'm
6:07attaching at this point.
6:08Boop, devs, done.
6:10Now I need to create the user account.
6:13So I'm going to create a new user account here we'll
6:16call this Knox dev, something really simple,
6:18and they do need console access that way
6:21they can actually browse to the CloudNine console
6:26if they need to go through the AWS console to do that.
6:29I'll let it auto-generate a password for me
6:31and I'm going to turn off this prompt
6:33to create a new password at the next sign in.
6:36That way, I can just use this auto-generated password.
6:39It's a lab environment.
6:40I can be a little willy nilly, if you will, but you,
6:44in an environment where you've got the company credit
6:46card on file be a little more careful with that.
6:49Let's go next and here we go.
6:52So what group does that member need to be a part of?
6:54Right there, they're going to join the devs group like so.
6:58I'm going to click Next and review and create.
7:01So let's do it.
7:02Create user, Yay, there we go.
7:04So what do I need?
7:05I need the sign in URL, I need the username,
7:08and I need the password.
7:10There's the password.
7:11So I'm going to copy all of these things
7:13to a text file real quick.
7:15Here we go, copy the username, Oh, I lost my-- come back here.
7:20Come back here.
7:21There we go.
7:21Yeah, better.
7:22OK, copy the username and then copy this password
7:27right there and great.
7:30Awesome.
7:30So let's just make sure that the user could actually
7:34access the CloudNine console.
7:36So what I'm going to do is I'm going to sign out right there.
7:39I'm going to grab the sign in URL
7:41for this new user named Knox dev, paste it, Enter,
7:46and we will get in the--
7:49I know the name is NOx dev so I'm just
7:50going to copy the password, type Knox dev
7:53and paste it right there and click Sign In.
7:58So with that sign in done, I don't
8:01need LastPass to remember this sample account.
8:04Now, what I can do is I can search for CloudNine
8:07and as long is I can browse to this right here,
8:10that's a really good sign.
8:12Let's see, no errors, no warnings.
8:14Yeah, that looks great.
8:15So if I choose Create Environment,
8:17does it give me any gap?
8:18Nope this is great.
8:20So in the next video, we can move to the very next step
8:23where we create the environment and explore what all we can do.
8:27I hope this has been informative for you
8:29and I'd like to thank you for viewing.
Create a Cloud9 Environment
0:00[AUDIO LOGO]
0:06So now that our user has been created
0:08and they have access to get to Cloud9, what comes next?
0:13They then need to actually build a Cloud9 environment.
0:16Cloud9, at the end of the day, really just
0:18runs on an EC2 instance.
0:20So in this video, we're actually going
0:22to deploy the cloud nine environment
0:24for that specific user.
0:26Let's get started.
0:28All right.
0:29So this is where we're picking up where
0:31we left off on the last video.
0:33You see effectively what are we really doing?
0:35We're spinning up a new EC2 instance.
0:37And a cool thing about this is we
0:39do get to pick the size of the EC2 instance.
0:43If you're like me, sometimes--
0:45sometimes, I'm not going to say all the time, I'm not--
0:48I would never ever admit to this out in the wild.
0:53But sometimes my Docker containers get a little big.
0:58OK?
0:59It happens to the best of us, right?
1:00We're working with a large node project or something like that.
1:03And all of those dependencies.
1:05We've all been in dependency hell before.
1:07Next thing we know, our container
1:09may be a couple of gigs or two or three gigs.
1:14It might be a big container.
1:16And what we find out pretty quickly
1:18is the one gig, one vCPU instance here
1:22that is free tier, that's nice.
1:25It's free.
1:26It might be just a little too small for really big projects.
1:30But for really basic projects and exploring
1:33what all Cloud9 can do, well, that's
1:36a great way to actually get going.
1:38What I'm going to do right now is
1:40I am going to go full screen like this, that way we get rid
1:43of that menu bar.
1:44And we can see this a little better.
1:46So what I'm going to call this?
1:47I'm going to call this knoxdev-env.
1:51That's going to be the name of my environment.
1:53I don't have to give it a description.
1:55This is going to be a newly provisioned EC2 instance.
1:59And for my basic use case right now,
2:02I'm just going to leave this in micro.
2:03You can click additional instance types.
2:06And you can see we can get pretty big instances
2:09if we need to like 384 gigs of RAM and 96 CPUs.
2:13What is that all about?
2:14Probably someone who's doing like machine learning
2:17and modeling on it or something like that.
2:18But nonetheless, you can get pretty big.
2:20Not every single EC2 instance type is supported.
2:25You're seeing T, C, and M. But that's still a pretty good list
2:29that you get to pick from.
2:30So I'm leaving this.
2:32Right now I'm going to go back to T2 micro
2:34because it's the free tier.
2:35And for my little example, that's all I need.
2:38For the OS, that is what platform is right here.
2:40We see I've got Amazon Linux 2 or Ubuntu 1804.
2:45Amazon Linux 2 is extremely lightweight.
2:47You still get a shell that you can interact with.
2:50It is basically like working with any other virtual machine
2:53that you're SSHed into.
2:54Now this is a good one, timeout.
2:56What does this all about?
2:57This is cost saving.
2:58If I disappear for 30 minutes, it basically
3:01takes a state save of the current environment
3:06that I'm in, and then sleeps the virtual machine effectively.
3:11It's almost like closing the lid on your laptop.
3:13And then you pick it you open the laptop back up,
3:16it takes a half a second to warm up.
3:18And then picks up exactly where you left off.
3:20That's basically what this is.
3:22So your timeout is after 30 minutes
3:24it goes into a hibernation state where you can awaken it
3:29very simply by just navigating back to it.
3:31Now the connection thing here.
3:34In my case, I'm going to choose SSH.
3:36Why?
3:37Because we did not assign the privileges
3:41for our current user.
3:43The current user who is working on building this environment.
3:46It tells you right here these IAM resources will be created.
3:51It's trying to create roles in this case.
3:53Specifically, these are the roles
3:55for the SSM, roles that exist right here.
3:58And because the user doesn't have the ability
4:01to create these roles, if I were to try and use AWS Systems
4:06Manager, it would file.
4:07So in this case, I'm going to choose SSH,
4:10and this will now succeed on the creation deployment.
4:14So give it a create, and there she goes.
4:18No errors.
4:19And it's underway.
4:20Now you see right here?
4:21This right here, this open button
4:23is how you actually get to the environment.
4:26That's what you want to look for.
4:27So give that a click, and you'll see
4:29it's going to take just a minute to spin up here.
4:32So let it spin and then come back to it when it's done.
4:35It takes about a minute to pass.
4:38And this is where we land.
4:40So what you're looking at here is
4:41the layout of the actual IDE.
4:45You have, first of all, notice the far left side,
4:48you've got three things that you can navigate to.
4:51This one is the File Explorer.
4:54This is what you're looking at right here on the screen.
4:56We're looking at a hidden folder right here called C9.
5:00This is where we actually configure our debug environment
5:04and our build environment.
5:06We'll be able to create our own folders with our own file
5:09structures down here and deploy our code whenever we want.
5:13Beyond that, I could use Git right there on the spot
5:16if that's what I wanted to do.
5:17I could absolutely hit Git clone and then
5:19clone my remote repository in and work with Git
5:23directly in the shell.
5:24Next up, speaking of Git, there it is.
5:27That's the next one on the list.
5:28If we give it a click, if I were actually
5:30working with any repositories, you
5:31would be able to see things like the branch
5:34that we're currently working on.
5:36Any files that haven't been staged.
5:38Anything that needs to be committed.
5:39The ability to push or pull repositories.
5:42This is all going to be contained right here.
5:44It's an exhaustive tool for working with source control.
5:47And lastly is at AWS Services right here.
5:51So when we look at AWS Services, it
5:53tells me we have a connection.
5:55And we even see the data center that we're currently
5:57running this in.
5:58The US East Ohio data center.
6:01If I expand this, we see all of the services
6:03that we could potentially interact with directly
6:06in the IDE.
6:08So if I expand Lambda here for a second, oh-oh, yeah.
6:11You might be and not be able to see because the font is
6:14really small.
6:14So it's failed to load resources.
6:16What's that all about?
6:18Well, our user still doesn't have permissions to see
6:21these kinds of resources.
6:22They can't see things like S3 buckets or Lambda.
6:26That's what we have to go back and give them permissions
6:28to interact with these resources if they're
6:30going to be developing on it.
6:32Now that being said, what else can we do while we're here?
6:35Well, it's worth pointing out that down here at the bottom,
6:38this is your terminal, you can resize this as needed.
6:41You can say aws --version to see what the version of your AWS
6:46CLI is currently working with.
6:48You can do sam --version to see what the SAM AWS
6:52CLI is currently working with.
6:55You can do git --version, there's your Git version.
6:58And docker --version.
7:02Let's see.
7:04Yep, there it is.
7:05We see Docker.
7:06See, all of these things were baked into this from default.
7:10You also have this welcome screen
7:12right here where it gives you some documentation, security
7:14best practices.
7:15You can even change the theme of the editor
7:18that you want to work with.
7:19So dark, gray, or light, it's all right there.
7:22As well as the keyboard mode, if you
7:23want to change that keyboard mode for whatever reason
7:26if you're masochistic and you want to use them.
7:29I joke.
7:30I joke.
7:30But nano is better.
7:32I said it.
7:33I said it.
7:33Got it of my chest.
7:34Look, it also shows you can get started with creating a file,
7:37uploading files from your local computer
7:40into the IDE environment, or cloning
7:42a repository from GitHub.
7:45Also take note that these are tabs across the top.
7:47Much like any other IDE, I can close this
7:50and I can click the plus button to ask
7:52me, what are all the things that you want to open?
7:54Would highly recommend checking out open preferences
7:58because there are a lot of things
7:59that you can do configuring your actual instance like your--
8:04what runtimes and what programming languages
8:06you actually want to support.
8:08So you can go to look and see like Python support
8:10and see the Python 3 is enabled.
8:13So if I were to say python3 hyphen,
8:17is it lowercase V or uppercase V?
8:18Let's find out.
8:19Oh, there's a lot of stuff going on here.
8:20Doesn't like that.
8:21There we go.
8:22Let's see.
8:24There that's better.
8:24I just did python3 --version.
8:27We see that by default, it is running Python 3.7.16.
8:31So this is--
8:34I'm not going to say a little old, but it's a little old.
8:37I mean, we're on Python 3.11 right now.
8:40And Python 3.10 introduced some really cool features like
8:44the match statements.
8:45So that's one of those things, anyways.
8:47I digress.
8:48This is-- oh, oh, other here.
8:50Here's your debug terminal over here on the left hand side--
8:53or on the right hand side, excuse me.
8:55You also have a filter.
8:57So if you're looking for specific files or specific text
9:00within a file.
9:01And then right above that, you actually
9:03have the chat box where you can collaborate on what is going on
9:07in your IDE environment.
9:09So we explored some pretty cool things here in this video.
9:12This IDE does a lot of cool stuff.
9:14But still could be better, right?
9:17Because we still need to get access to these other items
9:20so that we can work on Lambda functions and such.
9:23One final thing that I'll point out
9:25is do explore what all you can do within these menus.
9:28Things like code formatting can be defined here.
9:32And as well as showing you the hotkeys to automatically format
9:35the code.
9:35You can do-- let's see.
9:37Where did it go?
9:38I just saw it.
9:38It was really cool.
9:39Oh, right here our view, you can find even more themes
9:43right here below.
9:44So if you want to explore some different color themes
9:46for your IDE, you can do that.
9:48You can also adjust things like font size,
9:50where it shows you the hotkeys for adjusting font size.
9:53Really, really good stuff that all exists right here
9:56in these menus at the top.
9:58So there, with all that being said,
10:00we've now launched into the IDE, explored it a little bit,
10:03and we're ready to get started.
10:05We're ready to start hacking.
10:06So that's what we're going to do in the next video.
10:09We got to make sure we've got the permissions set
10:11up so that we can start actually working on building
10:13and deploying our code.
10:15I hope this has been informative for you,
10:17and I'd like to thank you for viewing.
Adjust User Permissions
0:00[AUDIO LOGO]
0:06What you find out pretty quickly is
0:08it's cool that user can get their foot in the door
0:10and they actually have the IDE where
0:12they can develop code and ship code
0:14and check it in to Git repositories.
0:16But if they actually need to push deployments out there
0:20into the world, like deploying a Lambda function or an API
0:24gateway, they'll find out pretty quickly
0:26that the default user group that we've given them
0:29isn't sufficient.
0:30So in this video, we're going to circle back to those roles
0:33and permissions and give our user additional roles that
0:36can allow them to deploy a SAM template.
0:39The SAM template is going to be a Lambda resource and an API
0:44gateway to serve as a proxy that sits in front of it.
0:47Let's go.
0:49So in the previous video, we got launched into the IDE,
0:52and we were really excited to start
0:55deploying Lambda functions.
0:57But it tells you right here, failed to load resources,
1:00because it can't even look anything.
1:01If I were to try and create a Lambda SAM application
1:05by right clicking on Lambda and clicking on it,
1:08it would just blow up on me because this user doesn't
1:10have any of the permissions they need to do those things.
1:14So here's what I'm going to do.
1:15I'm going to go ahead and get logged out, sign back
1:18in as my administrator role.
1:20Let's go ahead and get signed all the way out here.
1:22Log back in.
1:23I'm going to choose sign in using my root user email.
1:27We'll go back to my last pass, go ahead next,
1:30sign in, multifactor, and we're getting signed right back in.
1:36So what I need to do is I need to jump back into my IAM
1:39environment right here, and then we're
1:42going to go back to my user group
1:43and alter the permissions that my devs actually get here.
1:47So I'm going to jump into my devs
1:48and I'm going to jump over to the permissions.
1:50We need to add some additional policies right here,
1:54including a custom inline policy that we're
1:57going to create on the fly.
1:59So I'm going to choose attach policies.
2:01And the first thing I'm going to do
2:02is make sure these guys can do whatever they want with Lambda.
2:05So I'm going to search for Lambda
2:07and I'm going to look for the full Lambda role.
2:10It's right down here towards the bottom.
2:12AWS Lambda full access.
2:15I'm going to add that permission right now there.
2:18Now they've got it.
2:19And now also what I need to do is make sure
2:22that they can deploy and execute API gateway tasks.
2:26So let's just search for API.
2:28They might have not like gate.
2:29OK hang on, hang on.
2:30Where would you go?
2:33Oh duh, I'm looking at the existing roles, not
2:36the permissions or the policies that I'm trying to attach.
2:39So let's go and search for add policy and search for API one
2:44more time.
2:44And then we'll see Amazon API gateway administrator.
2:49I'm going to check that right there.
2:50And I'm also going to be looking for Amazon API gateway invoke
2:55full access.
2:56That is what I want to add into these right here.
2:59So I am going to add these permissions into the mix.
3:03Now they have the API gateway items that they need.
3:06But there's still a lot more that they
3:08need to interact with S3.
3:11They need to create an S3 storage account.
3:14Why?
3:15Because we're going to be shipping
3:16code to a Lambda environment.
3:18And the way that works is we first ship code to S3
3:21where Lambda then picks it up.
3:23Who's doing all this shipping?
3:25Anyways CloudFormation.
3:29You can think of CloudFormation as a YAML
3:33defined template that deploys groups of cloud resources.
3:38To me, the thing that I am most familiar with in this world
3:42with that is like Docker compose.
3:44If you're coming from the Azure world,
3:46this is also like ARM templates.
3:48So CloudFormation is a YAML template
3:52that says and defines how groups of resources
3:55are supposed to be deployed at the same time
3:58and interact with each other.
4:00We also define things like roles and permissions
4:03that all get created at the same time.
4:06So this user is going to need all sorts of stuff
4:08at the end of the day, or the devs
4:10are going to need all sorts of stuff.
4:11So I'm going to create an inline policy,
4:14and we're just going to paste in some JSON.
4:16Now where can you go to get this JSON?
4:18I'll show you.
4:19It's github.com/dataknox/awssamples.
4:27Brings it up right here.
4:28Now you'll see we are currently working on the DVA-CO2 exam.
4:32And here's the Cloud9 folder.
4:33This will grow over time, there will
4:35be more folders and more code samples
4:37here as the course progresses.
4:39This is just one of the first things I'm recording.
4:41And right here you see policy.json.
4:43This is what we want to paste in to get all of this to work.
4:47So do raw, there we got the raw text.
4:51I'll Command-A to highlight everything, Command-C to copy.
4:54Jump back to the console.
4:56Delete all this out.
4:57Paste all this in.
4:59And I scroll down, I see no errors.
5:01So I'm going to choose review policy.
5:04We're going to go ahead and give this a name like DevCloud9.
5:10How about SAM?
5:11Like that.
5:11DevCloud9SAM.
5:12That'll be the name of the policy
5:14that I'm creating here, because that's what I'm trying to do.
5:16I'm trying to give my devs who are working
5:18in Cloud9 the permissions to do what they
5:20need to do with SAM resources.
5:23So at this point, my permissions should be good to go.
5:27What I'm going to do is I'm now going to log back out,
5:30sign back in as my IAM user.
5:34So let's do sign in to the console.
5:37I'm going to choose an IAM user.
5:39And I need to bring up my text document.
5:41One more time.
5:41There we go.
5:42Where did you go?
5:42Come on.
5:43Hang on.
5:45Oh, there it is right there.
5:47So this was the user ID.
5:51So let's go ahead and save the account ID is right there.
5:54Next.
5:55Flip back.
5:56I'll just grab the password since the username is knoxdev.
5:59That's simple enough.
6:00Knoxdev.
6:01Paste in the password and sign in.
6:04So now we're looking good.
6:06Let's jump back into Cloud9.
6:08You'll see how it's just going to pick up
6:10exactly where I left off.
6:11That's the big thing that I was stressing before, right?
6:14Give it a click.
6:16Let's see.
6:18And bring it back up exactly where I left off.
6:20See.
6:21Remember the last thing I did was Python 3 version?
6:23Yeah.
6:24Exactly.
6:24Right?
6:25Now I can jump into AWS over here, expand US East Ohio.
6:31And if I expand Lambda, there's no more error.
6:34Now it just says no functions found.
6:37Much better.
6:38Great.
6:39So now my user has the permissions
6:42that they need to interact with Lambda and API gateways.
6:46They now have what they need to use CloudFormation to deploy
6:52a stack, which is effectively the group of resources
6:55that were deployed together.
6:56That would include deploying an S3 storage account.
7:00So we've got everything that we need
7:03to actually build an actual function that's
7:06going to serve as an API.
7:08And that's what we're going to do in the next video.
7:10I hope this has been informative for you,
7:12and I'd like to thank you for viewing.
Create and Deploy a SAM Template
0:00[AUDIO LOGO]
0:06Now with those permissions in place,
0:08our user can move forward with actually creating a lambda
0:11project.
0:12And that's what we're going to do in this video.
0:14We are actually going to create a lambda project from scratch.
0:17I've got some custom code that we're going to use.
0:19It's still pretty hello world at the end of the day.
0:21But still we're going to actually get
0:23this built and then deployed out there into the real world.
0:27In the next video, we'll test it out.
0:28So without further ado, let's jump back into Cloud9,
0:32build a lambda project, deploy it out there
0:35into the real world, then we'll check it out.
0:37Let's go.
0:38All right.
0:39So now we're ready to see this in action.
0:42I know I'm pretty excited about this.
0:44What I'm going to do is I'm going
0:45to let Cloud9 do a lot of the heavy lifting for me.
0:49I want to create a python based function.
0:53And just to kind of tell you what I'm trying to do,
0:55I just want to make a post with a payload in the body of my API
1:01request.
1:02This is going to be a post request.
1:04And in that, I'm going to say I want
1:06to get some Star Wars data.
1:08I might define the type of data that I
1:11want to get as something like a planet data.
1:14And then I might say that the detail that I'm trying to get
1:19is maybe tatooine, a important and well-known planet
1:25in the Star Wars universe.
1:27So this is how the payload is going
1:29to look that I'm posting in to the actual lambda function.
1:34And I want the lambda function to reply back
1:37with something that says I was able to parse
1:40your request you said tatooine.
1:41That's effectively what I'm trying to do here.
1:43So to bring all of this to life, like I said,
1:46I'm going to let Cloud9 do a lot of the heavy lifting.
1:49So I'm going to say create a lambda SAM application.
1:53So we'll give that a click by right clicking on it
1:55and then we say what is your environment that you
1:57want to run with?
1:58I'm going to say Python 3.9.
2:00Notice that is the latest image that we can get.
2:02This is not python 310 or 311.
2:05So you can't use things like the match statement.
2:07You're going to have to use if or elif or whatever
2:10the case is.
2:10So Python 3.9 is fine.
2:12I'm OK with the Intel 64-bit.
2:15Even though I am, you know you've probably
2:17may have noticed that I'm on a MacOS,
2:19I am using the ARM architecture.
2:21But that's fine.
2:22Now what are we trying to do?
2:23We're trying to do a hello world basic SAM application.
2:27So that's what I'm going to click right here to give it
2:29an application template.
2:31And I'm just going to let it run in this folder.
2:33The root of my folder is going to create my entire project
2:36right there in the root of my folder.
2:38So I'll give that a click.
2:40And it says enter a name for your new application.
2:43And I'm going to call this sw.app for Star Wars app.
2:48I'll press enter right there.
2:49And it's underway.
2:51If I now click back into the folder explorer here,
2:54it says, oh, AWS toolkit compiled SAM application sw.app
2:59and added the launch configurations to launch.json.
3:03So that means the actual debugging information is there
3:06now.
3:07You can open launch.json to explore it right here.
3:09And you see that's how it's kind of got the entire development
3:12environment set up.
3:14Now over here on the folder explorer,
3:16you see the sw.app folder right there.
3:20If I expand it, look at this.
3:22It actually initialized a full project.
3:25First thing that you want to take a look at is template.yml.
3:28You'll have to double click on this to bring up template.yml.
3:32Now what am I looking at here?
3:34This is the template that is going to deploy
3:39all of your resources.
3:41First is your API gateway, and the lambda
3:45function that is down here.
3:47We see how it's actually going to be handling things
3:49like permissions.
3:51This is the permission that is assigned to the API gateway.
3:54And I think this is one of the more important things
3:56that you're going to see.
3:57Right here under properties, we're
3:59establishing an endpoint that the API will hit,
4:03as well as what is the type of methods that it will accept.
4:08So if I wanted this to access the root endpoint,
4:11I can put the forward slash here,
4:13and I'm going to change my method to be post.
4:17So I'll Command-S. Make sure you save
4:19these things as you go along.
4:21This is the only change I need to make for a basic ARM--
4:24or excuse me, a basic SAM template right now.
4:28Now I also see I've got ReadMe docs and the Py initialization.
4:32Within the actual folders themselves,
4:34we actually see the hello world folder.
4:37This is where the application itself lives.
4:40We see I've got app.py.
4:42If I double click that, this is where the lambda code lives.
4:45Now if this is your first time seeing lambda, at minimum,
4:49you have to have at least one function called lambda_handler.
4:54It takes the event itself which contains things
4:58like the body of the requests that came in,
5:01as well as headers of the requests, and so on,
5:04as well as a context as to where this is being run.
5:08Now I'm going to replace almost all of this code
5:10with my Star Wars code.
5:12So let's go ahead and do that.
5:14I'm going to go back to that GitHub repository,
5:16github.com/datanox.
5:18So let's go to github.com/datanox.
5:20And then we'll just go straight into AWS samples.
5:26Jumping into the Cloud9 folder.
5:28And we see app.py39, that's for version--
5:32Python version 3.9.
5:33So that's what I want.
5:35I'm going to choose raw right here, grab the entire payload,
5:40Command-C, jump back to the development environment,
5:44highlight everything, Command-V, and Command-S to save.
5:49So you can see what it's doing right here.
5:51The payload, recall, is going to have two keys--
5:54type and detail.
5:58So as the payload comes in, it's going to be known as an event.
6:01And from there, we could parse that event as a dictionary.
6:05Type is the first key, and then details are right here.
6:09So if we're saying the body of tatooine--
6:13as detailed tatooine, set the response body
6:16to be hello tatooine reply with a status code of 200
6:20and a json payload of the actual body itself.
6:23Just like that.
6:25That's what we're doing right here.
6:26Not particularly complicated.
6:28If you are building your own code
6:30and you had your own requirements that
6:32are necessary, you can specify those requirements
6:35in requirements.text.
6:36That's, of course, for python libraries.
6:39If you are working with say node,
6:41you would want to look for package.json,
6:43and edit that section as needed.
6:45So this is the actual code itself.
6:49Now that I've got all of this stood up, what comes next?
6:53Well, the way this is going to work, what we need to do
6:57is we actually need to build this entire project
7:00as a container.
7:01So what I'm going to do in the terminal
7:03is I'm going to move into the sw.app folder.
7:07The commands that I'm going to run right here, they have
7:10to be run in the same path as the template.yml file,
7:15because that's what the YAML file really depends on.
7:17So being in the route of my project in the same folder
7:20if I type ls here you see I'm in the same folder
7:23as template.yml.
7:24Now what I can say is sam build, and then specify use container.
7:32You're going to use a container to build this.
7:34So I'm going to press Enter.
7:36Boop, there it goes.
7:37And now it's actually downloading the image itself
7:41before it performs the build.
7:42You'll also see new folders get created
7:45where the actual build folder, the
7:47build artifacts are going to be kept.
7:48So I'm going to let this run.
7:50We're going to circle back to it once the container has
7:53been successfully built.
7:56All right.
7:56So now that gets done, it's done building.
7:59That's nice.
8:00And we see that right down here, the font again is really small
8:03and I can't zoom right here.
8:05I've been trying to zoom in and it won't let me zoom.
8:07But it does say you have some commands that you can run next.
8:11We can validate the actual SAM template itself.
8:14Make sure that looks good.
8:15We can invoke a function locally,
8:17basically spinning up that new EC2 instance behind the scenes,
8:21shipping the code and invoking it.
8:24But really what we're here to do is deploy.
8:27To deploy this, we have to say sam deploy
8:30with the option of guided.
8:32So I'm going to type sam deploy --guided.
8:35But before I press enter, I'm going to scroll up
8:38and I'm going to bring this terminal up quite a bit
8:40because there's a lot that goes on whenever we actually
8:43do this.
8:43So I'm going to press enter, and we're
8:45going to take a look at what it's doing.
8:46So what's the name of the application that we're
8:48going to be deploying?
8:49I'm going to call this Star Wars App, S-W-A-P-P and press Enter.
8:54Then what's the region?
8:55I'm OK with leaving this in the east or the us-east-2.
8:58So I'll just press enter to accept that as the default.
9:01The next thing is confirm changes before you deploy.
9:04Lowercase Y. Then it says do you want to allow the SAM CLI IAM
9:09role creation.
9:10I have to.
9:11We're going to press Enter.
9:12Disable rollback.
9:15I'm just going to say yes to all of these things.
9:17So there we go.
9:18The helloworld function may not have authorization defined.
9:22Basically, it's say we looked at your code,
9:23we looked at the API template and we didn't
9:27see how auth would be handled.
9:29So this is going to be open.
9:30Are you OK with that?
9:31I'm going to say yes.
9:32Do you want to save arguments to a configuration file?
9:35I'm going to say yes.
9:36And then I'm not going to overwrite the configuration
9:39file name, nor am I going to overwrite the configuration
9:42environment.
9:43So I press enter and there she goes.
9:47OK.
9:48So the first time I ran that, you may have noticed that,
9:50that it actually threw an error at me where
9:53it said it was unable to--
9:55it said there was a put object iteration, which
9:57means it was trying to update something that was already
9:59existing.
10:00Basically, I had some old stuff sitting in my AWS environment
10:03and that blew up the build.
10:06It blew up one more time because it actually
10:09needs S3 full access to create and upload and edit S3 buckets.
10:14So now that that's been granted to the devs group here,
10:17we're going to jump back into Cloud9.
10:20I knew I forgot something.
10:21It was going to be that one S3 full access permission.
10:24So with that being said, now I can jump back into that user
10:27and get this deployed.
10:28So sign back in with that user, jumping back
10:31into the Cloud9 environment, I'm going to open the IDE.
10:34And it should pick up immediately where I left off.
10:37So there we go.
10:38No, I'm not going to try using Vim mode.
10:40It's just not-- it's just not for me.
10:41All right.
10:42We're going to go up.
10:42We're going to build using the container one more
10:45time just to make sure I've got a fresh build.
10:47I'm going to hit up a couple of times.
10:48Do the deployment guide.
10:51We'll call this Star Wars App in the east-us.
10:54Yes to all of the things.
10:57There we go.
10:58Y, Y, Y, lowercase Y, uppercase Y,
11:01and leave those as the default.
11:05Yes.
11:05But one last thing.
11:06Whenever you are trying to update a stack,
11:08if the current state of the stack is in rollback complete,
11:11it will not let you progress.
11:13So I need to reset that one more time.
11:16So jumping back into CloudFormation,
11:18I see the rollback complete status.
11:20That means I have to delete this guy right here.
11:23We'll delete it.
11:24Delete stack.
11:25And give it a refresh.
11:27Make sure it deletes successfully.
11:28Sometimes it doesn't delete successfully because the S3
11:31bucket had already been created, in which case, ,
11:34you have to go into S3 and delete the bucket that exists
11:37right there.
11:38So you have to delete all of the items in the bucket,
11:40then empty the bucket.
11:42And that's how you get rid of your bucket.
11:43So now that I've deleted that stack,
11:45it's not in the rollback complete status anymore.
11:48Now I can go forward, deploy the stack, which will then
11:52have the permissions to actually create the S3 bucket, which
11:58will then be able to proceed with deploying
12:01the lambda and the API gateway.
12:02See, I told you these permissions were a real thing.
12:05They're really a [garbled] when it comes
12:07to working with the SAM CLI.
12:08OK, so here we go.
12:10Getting signed back in.
12:11There we go.
12:12There's the password sign in.
12:13I'm going to jump straight into Cloud9.
12:16Right here at the top, I've got it pinned.
12:18I'm going to open the IDE one more time.
12:22There we go.
12:23See, it's nice and snappy.
12:24How quick it could actually get the IDE environment
12:27brought back up.
12:28So here we go.
12:28Press enter a couple of times.
12:30We're going to build one more time, deploy, change
12:37the name to Star Wars App.
12:39Everything else is going to be the same
12:41that we've already done.
12:42Here we go.
12:43Not U, Y. There we go.
12:45Y, Y, enter, enter.
12:48There we go.
12:49So now it's recreating the required resources.
12:52This time, it should succeed, and we'll
12:54come back to it when it's done.
12:56All right.
12:57Much better.
12:58So now it actually creates what's called a change set.
13:01It tells you overall what the proceeding operations
13:04are going to be.
13:05We're going to be creating some new resources,
13:08creating some new roles, creating the API gateway,
13:11creating the lambda function.
13:12So I'm going to say yes.
13:14We're OK to proceed with the actual deployment itself
13:18after validating what is happening in the change set.
13:20I have type Y, press enter, and there it goes.
13:24We actually see the creation of the roles and everything
13:26like that happening in real-time.
13:29So it's just going to be streaming in every half
13:31second or so as things get created.
13:34So you can see it's actually going
13:35through the process of creating the lambda function,
13:38creating the API gateway, creating the permissions,
13:41all of that is now happening.
13:43And we should see the success status message come up
13:46here any moment now.
13:48Aha, there it is.
13:49Successfully created and updated the stack swap in the east-us.
13:54How do I know for sure?
13:56I'm going to go back to my console,
13:58let's go into Services, and let's first take
14:01a look at API gateway.
14:03We should now see an API gateway resource.
14:07Come on, get rid of that.
14:08There we go.
14:08There we go.
14:09There's the swap API gateway.
14:11That's great.
14:12I should also be able to go into lambda
14:14and see the lambda resource.
14:16So bring up the lambda function.
14:18And there's the swap hello world function.
14:21All right.
14:22Do they work?
14:23That's what we're going to find out in the next video.
14:25I hope this has been informative for you,
14:27and I'd like to thank you for viewing.
Test, Debug, and Fix Any Issues
0:00[AUDIO LOGO]
0:06In the previous video, we built and deployed a SAM project.
0:10This is the Lambda function with an API gateway
0:13standing in front of it.
0:14Does it work?
0:16You're going to find out pretty quickly
0:17there's a little bit more tweaking we need
0:19to do to make this really work, at least in the scenario
0:21that I have in mind.
0:22So without further ado, let's test out
0:24our Lambda function and our API gateway
0:27and make some adjustments where need.
0:29Let's go.
0:30All right.
0:31We might have a little bit of tidying up to do,
0:33but we're going to find out pretty quickly here.
0:36I'm going to jump into my actual Lambda function itself.
0:40This is where we can see how the Lambda function is
0:42designed to work overall.
0:44We can hit it via the API gateway, which
0:47then runs the function, gets the response,
0:50and returns it back to the API gateway.
0:52If I wanted to go to the Lambda function directly,
0:56I could go into the configuration
0:58and can configure a URL-- in fact, I can show you,
1:01here's the configuration right here.
1:03Function URL by default there isn't one
1:05because our trigger is actually based on the API gateway
1:09hitting the query.
1:10We can also review the actual code
1:12that is used to make this run so this is where the code actually
1:15looks.
1:16Now, with the test itself, we need
1:18to configure a test event to actually test this thing out.
1:22So we're going to be creating a new event.
1:24I'll call this mytester, something really simple.
1:28I'll leave this event sharing to be private,
1:31template doesn't really matter.
1:32And the actual payload itself that we're posting in,
1:36remember I need a type and a detail.
1:39So I'll delete this.
1:41Type this right here to open up a brackets.
1:44We'll say the type is going to be planet,
1:48and the next bit of payload is going
1:50to be the detail is going to be tatooine.
1:56Like so.
1:57There we go.
1:58So if I do Format JSON, make it look nice and pretty.
2:00Everything here looks good, so I'm
2:02going to save this test item and then click the Test button.
2:08Aha, success.
2:10Do you see it right there?
2:11There's the response.
2:12Status code of hello, the body came back as hello tatooine.
2:17We see how long it took to run, 1.24 milliseconds,
2:22was built for 2 milliseconds, memory size was 128 megs,
2:26max memory actually used was 36 megs.
2:29Yeah.
2:30So this is great.
2:31This actually worked.
2:33The function actually works the way we want it to.
2:35Now, does it work if I'm coming in from the outbound,
2:39the internet coming into the API gateway?
2:42Let's find out.
2:43If I jump to the services and jump over to the API gateway,
2:48this one might give us a little more trouble.
2:50We're going to find out.
2:51You're going to see why.
2:52If I jump into the Star Wars app that I have here.
2:55I see it registers my POST request.
2:57That's what we deployed.
2:59The POST request is at the root and I can test this right here.
3:02You see this Test button?
3:04If I give that a click, all I have to do
3:06is provide request body one more time.
3:09Just like before, we had type and the type was planet.
3:15Then I can say the detail was tatooine like so.
3:23Spell tatooine correctly, though, right?
3:25OK.
3:26There we go.
3:27So this should be what I need to test it out.
3:29Now, watch what happens.
3:30When I click Test right here, what
3:32are all these details that are coming back?
3:34What is this?
3:35Method complete with 502.
3:38Specifically, it says the Lambda execution failed because--
3:43it's kind of messy to see right here
3:45because it's all kind of messed up,
3:47it failed with status 200, which is the actual success message,
3:51but due to customer function error type.
3:54If you scroll up right here, it's blowing up on the line
3:58if event type equals planet.
4:01Why is it blowing up right there?
4:03I'll show you why.
4:04Because right here when I go back,
4:07you see this Lambda proxy?
4:10So the method comes in, the POST message comes in
4:13and it's got that payload.
4:15When the API gateway is set to serve as a true proxy
4:21to the Lambda function, it alters the payload.
4:25It actually changes the keys themselves and puts my--
4:30remember I had type and I had detail,
4:34it puts that inside of a key named body.
4:39And then there's other metadata about the actual event
4:44that goes in along with it.
4:45So my code is trying to parse directly to that key
4:49when it had to go through body first.
4:51So what I can do to fix this is I can just turn off the proxy.
4:55So if I go to Integration Request,
4:58I can say right here you see Use Lambda Proxy Integration right
5:02there, just turn that off.
5:03Boop, uncheck it.
5:04And say, OK, and then say, OK.
5:08There we go.
5:09Now, it's not quite done yet because there's still
5:12one other thing that has to happen.
5:15When the Lambda function runs, it returns a status code of 200
5:23with the payload itself.
5:25So what we have to do is we have to go into this method response
5:29and tell it when you get a status code of 200,
5:33here's how you reply back to the client.
5:35It's really misleading because you see HTTP Status 200 right
5:40here and you're thinking, well, it's already
5:42handling status code of 200.
5:44Give it a click, though, and you see it actually has no mapping.
5:47So right here it's asking, OK, when the response is coming
5:51inbound right here, what response code do
5:54you want to work with?
5:55I'll say if the inbound response is 200,
5:58I'll click the little check mark right here,
6:00then you can tell it when you expand
6:03this down here's what your response header should
6:05be, here's what your response body should be.
6:07But you can leave this alone right now.
6:10You don't actually have to edit anything because as long
6:12as it knows how to handle an inbound status of 200,
6:19then it'll just past the body, the response body, straight
6:22through back to the calling client.
6:25So I'll go to Test right here, I'll type in the body.
6:29One more time that was a type of planet
6:34and a detail of tatooine, like so.
6:40Scroll down to the bottom.
6:42Hit Test.
6:42And look at this.
6:44Now, we have successfully completed 200 the whole way
6:49through.
6:50We see the inbound body that came in
6:54and we see the response payloads coming back right there.
6:59So now the API gateway is successfully handling my Lambda
7:04function and we have now deployed
7:06a full SAM experienced from a Cloud Shell that is cloud nine.
7:12I hope this has been informative for you,
7:14and I'd like to thank you for viewing.
Team training path
Turn this skill into assignable team training
This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.
$749
seat / year