- Newest
- Most votes
- Most comments
This error suggests there's an issue with how the boto3 client is being initialized in your Lambda function. The error message "Session.create_client() got an unexpected keyword argument 'aws_account_id'" indicates you're passing a parameter to the boto3.client() method that it doesn't accept.
The standard way to create a boto3 client for Lambda is:
client = boto3.client('lambda')
If you're trying to access resources in another AWS account, you should use the AWS STS (Security Token Service) to assume a role in that account first, rather than passing an aws_account_id parameter directly to the client constructor.
Here's the correct approach for cross-account access:
# First assume role in the other account sts_connection = boto3.client('sts') assumed_role = sts_connection.assume_role( RoleArn="arn:aws:iam::<ACCOUNT_NUMBER>:role/<ROLE_NAME>", RoleSessionName="cross_account_session" ) # Then create a client using the temporary credentials credentials = assumed_role['Credentials'] client = boto3.client( 'lambda', aws_access_key_id=credentials['AccessKeyId'], aws_secret_access_key=credentials['SecretAccessKey'], aws_session_token=credentials['SessionToken'] )
This issue could also be related to:
- A version mismatch between the boto3 library in your development environment and the one in Lambda
- Custom code that's incorrectly passing the aws_account_id parameter
- A dependency that's wrapping boto3 and using incorrect parameters
Since you mentioned the code works with a new Lambda function and IAM role, it's possible that:
- Your current Lambda function is using an outdated version of boto3
- There might be permission issues with the current IAM role
- The Lambda environment might have corrupted dependencies
To resolve this:
- Check your code for any instances where boto3.client() is called with an aws_account_id parameter
- Update your Lambda function's dependencies, especially boto3
- If you're using Lambda layers, ensure they contain compatible versions of your dependencies
- Consider recreating your Lambda function with the correct dependencies
Sources
Lambda function to copy in S3 accross-accounts - Python code problem | AWS re:Post
Unable to import module 'lambda_function': No module named 'requests | AWS re:Post
answered a year ago
You have 2 options:
- Redeploy your lambda with the latest version of the boto3 SDK
- Manually roll back lambda runtime version to the one that worked. The process is described (badly) in this article: https://docs.aws.amazon.com/lambda/latest/dg/runtime-management-rollback.html#runtime-management-rollback-manual
answered a year ago
Relevant content
- AWS OFFICIALUpdated 3 months ago
