AWS accounts

Give learners access to AWS accounts.

This guide explains how to access an Amazon Web Services (AWS) account from Instruqt.

An AWS account is a container for your AWS resources. You create and manage your AWS resources in an AWS account, and the AWS account provides administrative capabilities for access and billing.

ā€” AWS documentation

Before you begin

You must have already built a track to which you can add access to an AWS account.

Service Limits AWS accounts have built in service limits. If you plan to deploy complex network infrastructure check to make sure you do not exceed the EC2 service quota defaults.

Access AWS accounts

It is best to add the Instruqt Cloud Client container to your track to give a learner access to an AWS account. Because the Instruqt Cloud Client container:

  • Exposes links to the AWS Console for the resources configured in the config.yml file, with the credentials required to log in.

  • Includes the aws CLI, pre-configured with the required credentials.

The AWS Console and the aws CLI make it easy for content developers and learners to access AWS resources from the sandbox.

It takes the following steps to give learners access to an AWS account:

  1. Add an Instruqt Cloud Client container to your track.

  2. Add an AWS account to your track.

  3. Add tabs to your challenges where you want to expose the AWS console or aws CLI.

Additionally, you can use:

  • A set of environment variables that are available in the aws CLI.

  • IAM policies and permissions.

Use the AWS Cloud Account template

Instead of building the track yourself, you can create a track with the AWS Cloud Template. The template includes:

  • The Instruqt Cloud Client container

  • A pre-defined AWS account

  • A challenge with tabs for AWS console and aws CLI

Step 1: Add an Instruqt Cloud Client container to your track

  1. Click the track where you want to add an AWS account to. ā†³ Instruqt shows the corresponding Track dashboard page.

  2. In the Sandbox section, click Edit to open the Sandbox page.

  3. Click + Add a host.

  4. Pick the Container host type.

  5. Input these values:

    FieldValue

    Hostname

    cloud-client

    Image type

    Choose your own

    Container image

    gcr.io/instruqt/cloud-client

  6. Click Show optional settings. Enter these values:

    FieldValue

    Ports

    80

    Shell

    /bin/bash

  7. Click Save host to add the container.

Step 2: Add an AWS account to your track

  1. Click + Add a cloud account on the Sandbox page. ā†³ The Add cloud account pop-up opens.

  2. Select the Amazon provider.

  3. In the Name field, enter awsaccount.

  4. In the IAM Policy field, enter the following JSON:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
            "Sid":"EC2DefaultAllow",
            "Effect": "Allow",
            "Action": "ec2:*",
            "Resource": "*"
        }
      ]
    }
  5. In the SCP Policy field, enter the following JSON:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "RequireNanoInstanceType",
          "Effect": "Deny",
          "Action": "ec2:RunInstances",
          "Resource": [
            "arn:aws:ec2:*:*:instance/*"
          ],
          "Condition": {
            "StringNotEquals": {
              "ec2:InstanceType": "t2.nano"
            }
          }
        }
      ]
    }
  6. Click Save to add the AWS account. ā†³ On the Sandbox page, you will see the new AWS account.

  7. Click Back to track to return to the Track dashboard page.

Step 3: Add tabs to expose the AWS console and aws CLI

  1. In the Challenges section of the Track dashboard, click Add new, and select Assignment.

  2. Input these values:

    FieldValue

    Tab name

    AWS account

    URL

    aws-ec2

    Description

    Learn to work with an AWS account

  3. Click Save.

  4. Click Tabs followed by Add new tab.

  5. Select the Your applications tab type.

  6. Enter/select these values to set the AWS console:

    FieldValue

    Tab name

    AWS console

    Select your host

    cloud-client

    Path

    /

    Port

    80

  7. Click Save to add the tab.

  8. Click Add new tab again.

  9. Select the Terminal tab type.

  10. Enter/select these values to set the aws CLI:

    FieldValue

    Tab name

    aws CLI

    Host

    cloud-client

  11. Click Save to add the tab.

  12. Click Back to track.

  13. Click Play track and test your AWS account track.

Environment variables

Adding an AWS account to your track also sets a list of environment variables that you can use in commands and scripts:

Environment variable

Description

INSTRUQT_AWS_ACCOUNTS

A comma-separated list of project names that can be used to fill ${NAME} in the variables below

INSTRUQT_AWS_ACCOUNT_${NAME}_ACCOUNT_NAME

This injects the account display name

INSTRUQT_AWS_ACCOUNT_${NAME}_ACCOUNT_ID

This injects the account ID

INSTRUQT_AWS_ACCOUNT_${NAME}_USERNAME

This injects the username that can be used to sign in to the IAM user

INSTRUQT_AWS_ACCOUNT_${NAME}_PASSWORD

This injects the password that can be used to sign in to the IAM user

INSTRUQT_AWS_ACCOUNT_${NAME}_AWS_ACCESS_KEY_ID

This injects the access key id for this account

INSTRUQT_AWS_ACCOUNT_${NAME}_AWS_SECRET_ACCESS_KEY

This injects the secret access key for this account

Example

This example shows the id of the AWS account from a terminal by using two environment variables. The value of the INSTRUQT_AWS_ACCOUNTS environment variable is inserted in the INSTRUQT_AWS_ACCOUNT_${NAME}_ACCOUNT_ID environment variable.

To follow along:

  1. Start your AWS account track and start the first challenge.

  2. Move over to the Cloud CLI terminal and enter the following command:

    eval echo "\${INSTRUQT_AWS_ACCOUNT_${INSTRUQT_AWS_ACCOUNTS}_ACCOUNT_ID}"

    ā†³ The terminal shows the id of your AWS account project.

Setting policies and permissions

AWS accounts have the following settings to configure policies and permissions:

  • Managed policies

  • Identity And Access (IAM) policies

  • Service control policies (SCP) policies

Setting managed policies

An AWS managed policy is a standalone policy that is created and administered by AWS.

ā€” AWS documentation

The managed policies method is easier than the IAM and SCP policies but may grant learners more than the minimum access required to complete a track. The following example grants Virtual Private Cloud (VPC) administrator access, which allows learners to create and manage VPC networks:

Update your AWS account by entering the following in the Managed Policies field:

arn:aws:iam::aws:policy/AmazonVPCFullAccess

And clicking Add.

See AWS managed policies on the AWS docs site for more information.

Setting IAM policies

IAM policies define permissions for an action regardless of the method that you use to perform the operation.

ā€” AWS documentation

For more fine-grained control, you can set IAM policies. The following example sets a managed policy that limits the EC2 instance types to only several t2 and t3 instances. Note the use of the pipe symbol | to indicate that a multi-line JSON policy will follow.

Update your AWS account by entering the following pin the IAM policy field:

|
    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "RequireLessThanXLInstanceType",
          "Effect": "Deny",
          "Action": "ec2:RunInstances",
          "Resource": "arn:aws:ec2:*:*:instance/*",
          "Condition": {
            "StringNotEquals": {
              "ec2:InstanceType": [
                "t2.nano",
                "t2.micro",
                "t2.small",
                "t2.medium",
                "t2.large",
                "t3.nano",
                "t3.micro",
                "t3.small",
                "t3.medium",
                "t3.large"
              ]
            }
          }
        }
      ]
    }

See IAM on the AWS docs site for more information.

Setting SCP policies

Service control policies (SCPs) are a type of organization policy that you can use to manage permissions in your organization.

ā€” AWS documentation

For more fine-grained control, you can also set SCP policies. The following example disallows EC2 instance types except t2.large.

Update your AWS account by entering the following in the SCP policy field:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "RequireLessThanXLInstanceType",
      "Effect": "Deny",
      "Action": "ec2:RunInstances",
      "Resource": "arn:aws:ec2:*:*:instance/*",
      "Condition": {
        "StringNotEquals": {
          "ec2:InstanceType": [
            "t2.large"
          ]
        }
      }
    }
  ]
}

See Service control policies on the AWS docs site for more information.

Awesome! Your learners can now access AWS accounts. But there is more. You can also give them access to:

Last updated