适用于 PHP 的 AWS 开发工具包
开发人员指南
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

使用环境变量中的凭证

使用环境变量以包含您的凭证将防止您意外共享您的 AWS 秘密访问密钥。我们建议您不要直接将您的 AWS 访问密钥添加到客户端的任何生产文件。许多开发人员通过其账户已经受损泄露密钥。

要对 Amazon Web Services,开发工具包首先检查环境变量中的凭证。开发工具包会使用 getenv() 函数来查找 AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_SESSION_TOKEN 环境变量。这些凭证称为环境凭证

如果您正在 AWS Elastic Beanstalk 上托管您的应用程序,可以通过 AWS Elastic Beanstalk 控制台设置 AWS_ACCESS_KEY_IDAWS_SECRET_KEY 环境变量,以便开发工具包可以自动使用这些凭证。

您也可以在命令行中设置环境变量,如下所示。

Linux

$ export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE # The access key for your AWS account. $ export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY # The secret access key for your AWS account. $ export AWS_SESSION_TOKEN=AQoDYXdzEJr...<remainder of security token> # The session key for your AWS account. This is needed only when you are using temporary credentials. # The AWS_SECURITY_TOKEN environment variable can also be used, but is only supported for backward compatibility purposes. # AWS_SESSION_TOKEN is supported by multiple AWS SDKs other than PHP.

Windows

C:\> SET AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE # The access key for your AWS account. C:\> SET AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY # The secret access key for your AWS account. C:\> SET AWS_SESSION_TOKEN=AQoDYXdzEJr...<remainder of security token> # The session key for your AWS account. This is needed only when you are using temporary credentials. # The AWS_SECURITY_TOKEN environment variable can also be used, but is only supported for backward compatibility purposes. # AWS_SESSION_TOKEN is supported by multiple AWS SDKs besides PHP.