1

I have a simple python script that I want to run as lambda function:

import boto3
from datetime import datetime, timedelta

get_last_modified = lambda obj: obj['SnapshotCreateTime'].timestamp()

rds_client = boto3.client('rds')
objs = rds_client.describe_db_cluster_snapshots(DBClusterIdentifier='db-cluster')['DBClusterSnapshots']

print(objs)

Usually in linux I will have the .aws/config file that contains the auth key and token. Where do add fill this values with lambda?

1
  • 1
    You will have to use IAM roles with the required permissions. Commented Jul 21, 2020 at 21:03

2 Answers 2

1

Please use IAM role attached with lambda function to set a New/Update Policy.

  1. Go to IAM
  2. Go to Roles
  3. Search and click on the IAM role associated with your lambda function
  4. Either Update You old Policy or Attach one from the existing Policies
  5. Save the changes.

Now you should be able to access the resource.

Note: If you are using IAM Roles with services, then you don't need to create any ACCESS_KEY or ACCESS_SECRET.

Sign up to request clarification or add additional context in comments.

Comments

1

To complement @Rahul's regarding modify lambda execution role, you also need to modify your code. It will not run on lambda in its current form.

Specifically, it requires a lambda_handler. For example:

import boto3
from datetime import datetime, timedelta

get_last_modified = lambda obj: obj['SnapshotCreateTime'].timestamp()
rds_client = boto3.client('rds')

def lambda_handler(event, context):

    objs = rds_client.describe_db_cluster_snapshots(DBClusterIdentifier='db-cluster')['DBClusterSnapshots']

    print(objs)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.