简体   繁体   中英

AWS - Connect to SQS from EC2

I am using the below code to fetch AWS credentials to connect to SQS. This is my personal credential and when I deploy this code in my qa or prod env , I shouldn't be using my credentials to connect to SQS. This code will be running in a EC2 container in AWS. What are the options available for me to connect to SQS without having to explicitly provide the user id / password like I have done below?

@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;
}
  • Create an IAM Role with sufficient permissions for the API requests your app will make
  • Assign the IAM Role to the EC2 instance

The AWS SDK will automatically retrieve credentials from the Instance Metadata. There is no need to provide any credentials.

See: Working with AWS Credentials - AWS SDK for Java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM