代码之家  ›  专栏  ›  技术社区  ›  Punter Vicky

AWS-从EC2连接到SQS

  •  -1
  • Punter Vicky  · 技术社区  · 6 年前

    我正在使用以下代码获取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;
    }
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   John Rotenstein    6 年前
    • 创建具有足够权限的IAM角色,以满足应用程序将发出的API请求
    • 将IAM角色分配给EC2实例

    AWS SDK将自动从实例元数据中检索凭据。无需提供任何凭据。

    请参见: Working with AWS Credentials - AWS SDK for Java