This rule raises an issue when the region configuration of the AWS client is hardcoded.

Why is this an issue?

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.

How to fix it

The solution involves externalizing these configurations using environment variables.

Code examples

Noncompliant code example

import boto3

s3 = boto3.client("s3", region_name = "us-east-1") # Noncompliant region_name is hardcoded

Compliant solution

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

Resources

Documentation