AWS SSO login to credentials as environment variables
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
AWS Single Sign-On (SSO) simplifies managing access to AWS accounts and applications at scale. It allows users to sign in with a single set of credentials to access multiple accounts and applications. However, developers often require access to AWS services through the AWS CLI or SDK, where credentials are typically set as environment variables. This article delves into how to use AWS SSO to store and retrieve these credentials as environment variables to seamlessly integrate with AWS CLI and SDKs.
Understanding AWS SSO
AWS SSO provides centralized access management across AWS services. It offers the following benefits:
- Centralized User Management: Administrators can manage user identities and permissions in one place.
- Single Source of Authentication: Users authenticate once to access multiple AWS accounts and other applications.
- Integration with Identity Providers: It supports integration with existing SAML 2.0 identity providers for authentication.
- Federated Access: Users gain federated access to AWS Management Console and CLI.
Setup AWS SSO
Prerequisites
- AWS SSO Enabled: Ensure AWS SSO is enabled in your AWS Organization.
- AWS CLI v2: AWS CLI v2 is required for SSO login.
- An Identity Source: AWS SSO must be configured to use an identity source.
SSO Configuration
Configure AWS SSO in your AWS administrator account.
- Access AWS SSO: Go to AWS SSO in the AWS Management Console.
- Set Up Identity Source: Choose an identity source, such as AWS SSO, External Identity Provider, or Active Directory.
- Configure User Permissions: Define user roles and permission sets tailored for different AWS accounts and applications.
Configuring AWS CLI for SSO
To authenticate and use AWS services with AWS SSO via the CLI, you must define profiles using the `aws` CLI.
Define an SSO Profile
The following example demonstrates how to configure the AWS CLI to use AWS SSO:
- `SSO session name`
- `SSO region`
- `SSO URL`
- `SSO Role name`
- `Account ID`
- `AWS Region`
Related reading
- AWS step functions and optional parameters
- AWS sts assume role in one command
- aws sts get-session-token fails with profile
- AWS System Manager Parameter Store vs Secrets Manager vs Environment Variation in Lambda, when to use which
- AWS System Manager start session An error occurred TargetNotConnected when calling the StartSession operation instance_id is not connected
- AWS The config profile MyName could not be found
- AWS Toolkit for Eclipse Installation fails on Eclipse Luna
- AWS Trust Policy Has prohibited field Principal

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.