This rule raises an issue when the region configuration of the AWS client is hardcoded.
Hard-coding configuration values directly into your function code is an anti-pattern. This practice couples your code tightly to specific deployment environments and makes it brittle, difficult to manage, and prone to errors.
The solution involves externalizing these configurations using environment variables.
import boto3
s3 = boto3.client("s3", region_name = "us-east-1") # Noncompliant region_name is hardcoded
import os
import boto3
region = os.environ.get("AWS_REGION", "us-east-1")
s3 = boto3.client("s3", region_name = region) # Compliant region_name is set through an environment variable