A developer is writing an on-premises Python application that uses the AWS SDK (Boto3) to retrieve objects from an Amazon S3 bucket located in a separate, secondary AWS account. The developer has configured the on-premises server with an IAM user's long-term access keys stored in the default profile of the local credentials file. The security team has created an IAM role in the secondary account named CrossAccountS3ReadRole that has the required permission to access the bucket. How should the developer configure the AWS SDK to retrieve the S3 objects using the permissions of the secondary account's IAM role?
- Configure a new profile in the AWS config file containing the target role's ARN and the source profile, and then initialize the SDK session using this profile name.Cevap
- BHardcode the temporary access keys, secret keys, and session tokens returned by a manual AWS CLI STS assume-role command directly in the application's initialization code.
- CConfigure the IAM user's trust policy in the local credentials file to trust the secondary account's S3 bucket, and initialize the S3 client using the default credentials provider.
- DStore the IAM role's ARN in AWS Secrets Manager and configure the SDK's default credentials provider to automatically query Secrets Manager to assume the role.
Cevap
Configure a new profile in the AWS config file containing the target role's ARN and the source profile, and then initialize the SDK session using this profile name.
Configuring a named profile in the AWS configuration file using 'role_arn' and 'source_profile' is the recommended way to handle role assumption in the AWS SDK. The SDK handles the API call to AWS STS (AssumeRole) using the credentials from the source profile and automatically manages the lifecycle and refresh of the temporary credentials.
Adım Adım Çözüm
Anahtar Kavram
AWS SDK Profile-based IAM Role Assumption
Tahmini Süre:1m 30s