Skip to content

How do I set up the AWS CLI so that I can work with an Amazon DynamoDB table on Amazon EC2?

3 minute read
0

I want to configure the AWS Command Line Interface (AWS CLI) to work with Amazon DynamoDB tables on Amazon Elastic Compute Cloud (Amazon EC2).

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Create an AWS Identity and Access Management (IAM) role

To create an IAM role, complete the following steps:

  1. Open the IAM console.
  2. In the navigation pane, choose Roles.
  3. Choose Create role.
  4. For Select type of trusted entity, choose AWS service, and then choose EC2.
  5. For Attach permissions policies, choose AmazonDynamoDBFullAccess.
    Note: Follow the security best practice of granting least privilege to perform a task.

Attach the IAM role to an Amazon EC2 instance

To attach the IAM role to an Amazon EC2 instance, complete the following steps:

  1. Launch an EC2 instance from an Amazon Linux Amazon Machine Image (AMI). Linux AMIs come with the AWS CLI installed.
  2. On the Configure Instance Details page, in the IAM role drop-down list, select the IAM role that you created earlier. Make sure that the subnet that you select is accessible from the internet.
  3. On the Configure Security Group page, choose a security group that allows SSH access from your IP address.

Connect to the Amazon EC2 instance through SSH

To connect to your Linux instance through SSH, complete the following steps:

  1. Connect to your Linux instance through SSH.
  2. Run the yum update command so that the software packages on the instance are up to date.

Configure the AWS CLI

To configure the AWS CLI to work with DynamoDB, complete the following steps:

  1. Run the aws configure command.
  2. When you're prompted for an AWS Access Key ID and AWS Secret Access Key, press Enter. You don't need to provide keys because you're using an instance IAM role to connect with an AWS service.
  3. For Default region name, enter the AWS Region where your DynamoDB tables are located. For example, ap-northeast-3. For a list of Region names, see Service endpoints.
  4. For Default output format, press Enter.
  5. Run the list-tables command to confirm that you can run DynamoDB commands on the AWS CLI.

Related information

Use Amazon DynamoDB with the AWS CLI

DynamoDB examples using AWS CLI

AWS OFFICIALUpdated a year ago