When an application on an EC2 instance needs to access Amazon S3, which is the MOST recommended way to grant permissions securely with temporary credentials without embedding access keys in the code?

1 / 1
Select an answer
CorrectB

Explanation

A question asking the recommended way to grant permissions to an EC2 app securely.

  • 1without embedding access keys in the codeAvoid hard-coding long-term keys
  • 2temporary credentialsCredentials that are automatically obtained and rotated = IAM role
  • 3grant permissions securelyGranting permissions with reduced leakage risk
AIncorrect

Write the root user's access key in the code.

The root user has the most powerful privileges in the account, and embedding its credentials in code is extremely dangerous.

The damage if leaked is enormous, and it is the opposite of a recommended method, so it is incorrect.

BCorrect

Assign an IAM role to the EC2 instance.

This is correct. When an IAM role is assigned to EC2, the app automatically obtains temporary credentials to access S3. There is no need to embed access keys in the code, and the credentials are rotated automatically, which is secure. This is the best practice.

CIncorrect

Hard-code an IAM user's access key in the code.

Even an IAM user's access key, when written directly in code, has a high risk of leakage and is troublesome to rotate.

It does not meet the requirement to safely use temporary credentials, so it is incorrect.

DIncorrect

Allow access with a security group.

A security group is a firewall that controls traffic (ports and IPs), not a mechanism that grants permissions (authentication/authorization) to AWS services.

It cannot be used to grant permissions to S3, so it is incorrect.

Key Takeaway

"Access AWS services from EC2," "do not embed keys," and "temporary credentials" point to the standard answer: an IAM role. Hard-coding the root key or access keys is forbidden. A security group controls traffic, not permission granting.