Selecione suas preferências de cookies

Usamos cookies essenciais e ferramentas semelhantes que são necessárias para fornecer nosso site e serviços. Usamos cookies de desempenho para coletar estatísticas anônimas, para que possamos entender como os clientes usam nosso site e fazer as devidas melhorias. Cookies essenciais não podem ser desativados, mas você pode clicar em “Personalizar” ou “Recusar” para recusar cookies de desempenho.

Se você concordar, a AWS e terceiros aprovados também usarão cookies para fornecer recursos úteis do site, lembrar suas preferências e exibir conteúdo relevante, incluindo publicidade relevante. Para aceitar ou recusar todos os cookies não essenciais, clique em “Aceitar” ou “Recusar”. Para fazer escolhas mais detalhadas, clique em “Personalizar”.

Credential providers - AWS SDK for C++
Esta página não foi traduzida para seu idioma. Solicitar tradução

Credential providers

To make requests to AWS using the AWS SDK for C++, the SDK uses cryptographically-signed credentials issued by AWS. At runtime, the SDK retrieves configuration values for credentials by checking several locations.

Authentication with AWS can be handled outside of your codebase. Many authentication methods can be automatically detected, used, and refreshed by the SDK using the credential provider chain.

For guided options for getting started on AWS authentication for your project, see Authentication and access in the AWS SDKs and Tools Reference Guide.

The credential provider chain

If you don't explicitly specify a credential provider when constructing a client, the SDK for C++ uses a credential provider chain that checks a series of places where you can supply credentials. Once the SDK finds credentials in one of these locations, the search stops.

Credential retrieval order

All SDKs have a series of places (or sources) that they check in order to get valid credentials to use to make a request to an AWS service. After valid credentials are found, the search is stopped. This systematic search is called the credential provider chain.

For each step in the chain, there are different ways to set the values. Setting values directly in code always takes precedence, followed by setting as environment variables, and then in the shared AWS config file. For more information, see Precedence of settings in the AWS SDKs and Tools Reference Guide.

The SDK attempts to load credentials from the [default] profile in the shared AWS config and credentials files. You can use the AWS_PROFILE environment variable to choose a named profile you want the SDK to load instead of using [default]. The config and credentials files are shared by AWS SDKs and tools. The AWS SDKs and Tools Reference Guide has information on SDK configuration settings used by all AWS SDKs and the AWS CLI. To learn more about how to configure the SDK through the shared AWS config file, see Shared config and credentials files. To learn more about how to configure the SDK through setting environment variables, see Environment variables support.

To authenticate with AWS, the SDK for C++ checks the credential providers in the following order.

  1. AWS access keys (temporary and long-term credentials)

    The SDK attempts to load credentials from the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables, or from the shared AWS credentials file.

    • For guidance on configuring this provider, see AWS access keys in the AWS SDKs and Tools Reference Guide.

    • For details on SDK configuration properties for this provider, see AWS access keys in the AWS SDKs and Tools Reference Guide.

  2. AWS STS web identity

    When creating mobile applications or client-based web applications that require access to AWS, AWS Security Token Service (AWS STS) returns a set of temporary security credentials for federated users who are authenticated through a public identity provider (IdP).

    • When you specify this in a profile, the SDK or tool attempts to retrieve temporary credentials using AWS STS AssumeRoleWithWebIdentity API method. For details on this method, see AssumeRoleWithWebIdentity in the AWS Security Token Service API Reference.

    • For guidance on configuring this provider, see Federate with web identity or OpenID Connect in the AWS SDKs and Tools Reference Guide.

    • For details on SDK configuration properties for this provider, see Assume role credential provider in the AWS SDKs and Tools Reference Guide.

  3. IAM Identity Center

    If you use IAM Identity Center to authenticate, this is when the SDK for C++ uses the single sign-on token that was set up by running AWS CLI command aws sso login. The SDK uses the temporary credentials that the IAM Identity Center exchanged for a valid token. The SDK then uses the temporary credentials when it calls AWS services. For detailed information about this process, see Understand SDK credential resolution for AWS services in the AWS SDKs and Tools Reference Guide.

  4. External process provider

    This provider can be used to provide custom implementations, such as retrieving credentials from an on-premises credentials store or integrating with your on-premises identify provider.

    • For guidance on one way to configure this provider, see IAM Roles Anywhere in the AWS SDKs and Tools Reference Guide.

    • For details on SDK configuration properties for this provider, see Process credential provider in the AWS SDKs and Tools Reference Guide.

  5. Amazon ECS and Amazon EKS container credentials

    Your Amazon Elastic Container Service tasks and Kubernetes service accounts can have an IAM role associated with them. The permissions granted in the IAM role are assumed by the containers running in the task or containers of the pod. This role allows your SDK for C++ application code (on the container) to use other AWS services.

    The SDK attempts to retrieve credentials from the AWS_CONTAINER_CREDENTIALS_RELATIVE_URI or AWS_CONTAINER_CREDENTIALS_FULL_URI environment variables, which can be set automatically by Amazon ECS and Amazon EKS.

  6. Amazon EC2 Instance Metadata Service

    Create an IAM role and attach it to your instance. The SDK for C++ application on the instance attempts to retrieve the credentials provided by the role from the instance metadata.

The credential provider chain can be reviewed at AWSCredentialsProviderChain in the AWS SDK for C++ source code on GitHub.

If you followed the recommended approach for new users to get started, you set up AWS IAM Identity Center authentication during SDK authentication with AWS of the Getting started topic. Other authentication methods are useful for different situations. To avoid security risks, we recommend always using short-term credentials. For other authentication method procedures, see Authentication and access in the AWS SDKs and Tools Reference Guide.

Explicit credential provider

Instead of relying on the credential provider chain to detect your authentication method, you can specify a specific credential provider that the SDK should use. You can do this by providing credentials in your service client's constructor.

The following example creates an Amazon Simple Storage Service client by directly providing temporary access credentials instead of using the chain.

SDKOptions options; Aws::InitAPI(options); { const auto cred_provider = Aws::MakeShared<Auth::SimpleAWSCredentialsProvider>("TestAllocationTag", "awsAccessKeyId", "awsSecretKey", "sessionToken"); S3Client client{cred_provider}; } Aws::ShutdownAPI(options);

Identity caching

The SDK will cache credentials and other identity types such as SSO tokens. By default, the SDK uses a lazy cache implementation that loads credentials upon first request, caches them, and then attempts to refresh them during another request when they are close to expiring. Clients created from the same Aws::Client::ClientConfiguration share a cache.

PrivacidadeTermos do sitePreferências de cookies
© 2025, Amazon Web Services, Inc. ou suas afiliadas. Todos os direitos reservados.