Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Creating a Basic Lambda Function to Shut Down an EC2 Instance

In this hands-on lab, we will create a basic Lambda function to shut down an EC2 instance. We will start by creating a custom IAM policy for the IAM role. We will then create a basic Lambda function using the newly created IAM policy and role, along with the provided Lambda function code. To verfiy that the new Lambda function shuts down our EC2 instance, we will also run a test to make sure it is all working correctly. The provided IAM policy and Lambda function code can be accessed from the lab guide and in the Additional Information and Resources section of this lab.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Aug 16, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create a Custom IAM Policy and Role for a Lambda Function

    1. From the AWS Management Console, navigate to IAM.
    2. Select the option to create a custom IAM policy for the Lambda service.
    3. In the IAM console, click Create policy.
    4. Select the JSON tab and delete the provided JSON.
    5. Copy the provided IAM policy from the GitHub repo or the lab guide and paste it in the JSON tab.
    6. In the IAM console under Roles, search for the newly created policy and add it to our role.

      Note: The IAM policy may take a few minutes to populate.

    7. Once populated, select the new policy and add it to the role.
    8. Add a role name, tags, and a description.
    9. Click Create role.
  2. Challenge

    Create a Basic Lambda Function

    1. In the Lambda console, click Create a function.
    2. Select Author from scratch.
    3. For the runtime, select Python 3.6.
    4. Select the newly created IAM role and delete the provided JSON.
    5. Copy the provided Lambda function code from GitHub or the lab guide and paste it into the role.
    6. Paste in your EC2 instance ID into the Lambda function code.
  3. Challenge

    Create a Test in the Lambda Console

    1. In the Lambda console under Code source, select the new function and click Test.
    2. Add an event name and click Create.
    3. In the EC2 console, verify the instance is running.
    4. Return to the Lambda console and run the test.
    5. Return to the EC2 console and verify that the basic Lambda function stopped the EC2 instance.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans