Utils
Create a boto3 session with the provided profile name. If an AWS role ARN is provided, the session will assume the role. There are two options for providing credentials:
-
Provide the profile name containing AWS credentials stored in the ~/.aws/credentials file (e.g., access key ID, secret access key, or session token). These credentials must belong to a principal (e.g., an IAM user) that has the necessary permissions to interact with the AWS services required by the application.
-
Provide the AWS role ARN, in addition to the profile name, to assume, which grants the necessary permissions to interact with AWS services. If a role ARN is provided, the profile's associated principal (e.g., an IAM user) must at least have the
sts:AssumeRolepermission. Additionally, the role to be assumed must have a trust relationship with the principal that uses the profile's credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile_name
|
str
|
The AWS profile name to use. |
required |
role_arn
|
Optional[str]
|
The AWS role ARN to assume. The default is None. |
None
|
duration_seconds
|
Optional[int]
|
The duration in seconds for which the credentials will be valid. The default is 3600 seconds (1 hour). |
3600
|
Returns:
| Type | Description |
|---|---|
Session
|
A boto3 session |
Examples: