Let's operate AWS of another account with Lambda boto3

Posted in aws, blog on November 4, 2020 by Henk Verlinde ‐ 1 min read

Let's operate AWS of another account with Lambda boto3

Introduction

Describes how to easily operate other AWS environments with Lambda boto3

Get referrer access key ID and secret access key

Follow the steps below

  1. Go to AWS service [IAM]
  2. User Press
  3. [AdministratorAccess] Select the user to which the policy is attached
  4. Press the Credentials tab
  5. Create access key
  6. Make a note of the Access Key ID and Secret Access Key

create dynamoDB with referrer

create table. Name it [sample_tbl].

Create a Lambda function in the referenced account

code below

import boto3

def get_external_dynamodb():
    client = boto3.client('dynamodb',
        aws_access_key_id=[access key id],
        aws_secret_access_key=[secret access key] ,
        region_name=[region code]
    )
    return client

def lambda_handler(event, context):
    external_dynamodb = get_external_dynamodb()
    external_table = external_dynamodb.scan(TableName = "sample_tbl")
    return external_table

that’s all