【问题标题】:AWS - Connect to SQS from EC2AWS - 从 EC2 连接到 SQS
【发布时间】:2018-10-17 21:28:03
【问题描述】:

我正在使用以下代码获取 AWS 凭证以连接到 SQS。这是我的个人凭据,当我在我的 qa 或 prod env 中部署此代码时,我不应该使用我的凭据连接到 SQS。此代码将在 AWS 的 EC2 容器中运行。有哪些选项可供我连接到 SQS,而无需像下面那样明确提供用户 ID/密码?

@Bean
public AWSCredentialsProvider awsCredentialsProvider() {

    ProfileCredentialsProvider profileCredentialsProvider = new ProfileCredentialsProvider(credentialsProvider);
    try {
        profileCredentialsProvider.getCredentials();
    } catch (Exception e) {
        throw new AmazonClientException(
                "Cannot load the credentials from the credential profiles file. " +
                        "Please make sure that your credentials file is at the correct " +
                        "location (~/.aws/credentials), and is in valid format.",
                e);
    }
    return profileCredentialsProvider;
}

【问题讨论】:

    标签: java spring amazon-web-services amazon-ec2 spring-cloud


    【解决方案1】:
    • 为您的应用将发出的 API 请求创建具有足够权限的 IAM 角色
    • 将 IAM 角色分配给 EC2 实例

    AWS 开发工具包将自动从实例元数据中检索凭证。无需提供任何凭据。

    见:Working with AWS Credentials - AWS SDK for Java

    【讨论】:

    • 谢谢@John。有没有办法通过使用安全组来实现这一点?
    • 安全组是网络防火墙。它们与凭据无关。
    • 感谢@John Rotenstein
    猜你喜欢
    • 1970-01-01
    • 2022-10-17
    • 2017-09-26
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 2020-07-27
    • 2021-07-17
    • 1970-01-01
    相关资源
    最近更新 更多