“Why isn’t it enough to allow the traffic with a security group when an EC2 instance writes to DynamoDB?”
“I thought writing the access key in a configuration file was the most reliable approach.”
AWS Certified Cloud Practitioner (exam code CLF-C02, CLF below) asks questions that have you choose how to give an application on EC2 permissions without placing an access key on the instance. The key points behind the wrong options are the difference between allowing traffic and having permission to act, and why access keys for the root user or an IAM user should be avoided.
This article is Question 29 of a series that explains CLF practice questions one at a time. The author wrote the questions to match the scope of the exam; they are not actual exam questions. Choose your answer first, then read the explanation.
Question
A company has an application running on an Amazon EC2 instance that writes data to an Amazon DynamoDB table. It wants to give the application only the permissions it needs, without placing a long-term access key on the instance. Which is the most appropriate method?
- A. Use an outbound rule of the security group to allow traffic to DynamoDB
- B. Set the access key of the AWS account root user in an environment variable on the instance
- C. Create an IAM role that allows only writes to the DynamoDB table, and attach it to the instance
- D. Create an IAM user, issue an access key, and write it in the application’s configuration file
Once you have chosen your answer, open the section below.
Show the answer (click to open)
Answer: C
When you attach an IAM role that allows only writes to the instance, the application automatically receives temporary credentials. You can give it only the permissions it needs, without placing an access key.
The answer is C
The correct answer is C.
You attach an IAM role that allows only writes to the instance. The application automatically receives temporary credentials, so you do not need to place an access key. Let’s look at the options one at a time.
Explanation of each option
A: Allowing traffic is not permission (incorrect)

A security group is a network gate that decides whether traffic passes. To write data to DynamoDB, in addition to the traffic getting through, you need IAM permissions.
As in the diagram, even if an outbound rule allows the traffic, the write is denied if there are no IAM permissions. Allowing traffic and having permission to act are separate things.
B: Do not use root user keys (incorrect)

The root user is a special user that can do everything in an AWS account. As in the diagram, if you use its access key, the application can do anything, up to deleting the table or closing the account. This goes against the requirement of only the permissions it needs.
As a rule, you do not create an access key for the root user. It is a long-term key, so if it leaks, everything in the account is at risk.
C: Attach an IAM role (correct)

You attach an IAM role that allows only writes to the instance. The mechanism is called an instance profile.
The application receives temporary credentials from instance metadata. The AWS SDK and CLI use them automatically. The temporary credentials are rotated automatically by AWS. If you change the role’s policy, credentials with the new permissions are delivered automatically.
You do not need to place an access key, and the permissions are limited to what is needed.
D: Do not place a long-term access key (incorrect)

An IAM user’s access key is a long-lived credential. You can keep using it until you delete or deactivate it.
If you write it in a configuration file, then, as in the diagram, it can be abused by a third party if it leaks through published code or backups. It also goes against the requirement not to place a long-term access key in the first place. For an application on EC2, use an IAM role.
Long-term and temporary credentials
Here is a table of the differences between long-term and temporary credentials. The big differences are whether you need to place them and who performs the rotation.
| Item | Long-term credentials | Temporary credentials |
|---|---|---|
| Examples | Access keys of an IAM user or the root user | An IAM role (an EC2 instance profile) |
| Where they live | You place them yourself in a configuration file, an environment variable, etc. | You do not place them. The instance receives them from instance metadata |
| How long they work | Until you delete or deactivate them | They have an expiration |
| Rotation | You do it yourself | AWS does it automatically |
Key points
- Giving an application on EC2 permissions = attach an IAM role
- Temporary credentials are delivered and rotated automatically
- Do not place access keys in configuration files or environment variables
- A security group allows traffic. Permission to act comes from IAM
The course articles explain how IAM roles work and why you should not create access keys for the root user in detail.
- Lecture 10, Part 5: IAM and least privilege, in the “IAM roles” section
- Lecture 10, Part 4: AWS accounts and the root user, in the “How to protect the root user” section
You can read all 14 lectures of AWS Cloud Practitioner Exam Prep in order from its series page.
The CLF-C02 Practice Questions series (100 questions)
All 100 questions with a reading guide: CLF-C02 Practice Questions
In this group (Questions 19–30: The shared responsibility model and security):
- Question 19: Principle of least privilege (IAM policies and SCPs)
- Question 20: Shared responsibility model (what AWS is responsible for with EC2 and S3)
- Question 21: Examples of shared controls (IT controls in the shared responsibility model)
- Question 22: Compliance reports and agreements (AWS Artifact)
- Question 23: Threat detection (Amazon GuardDuty)
- Question 24: Continuous vulnerability scanning (Amazon Inspector)
- Question 25: Discovering sensitive data in S3 (Amazon Macie)
- Question 26: Encryption at rest for S3 and managing the keys (SSE-KMS and client-side encryption)
- Question 27: Finding out who made a change (AWS CloudTrail)
- Question 28: A list of IAM users’ credentials (credential report)
- Question 29: Granting permissions to an application on EC2 (IAM roles) (this article)
- Question 30: Automatic rotation of database passwords (AWS Secrets Manager)
This series is the English edition of 【CLF-C02 試験対策問題】, originally written in Japanese.


コメント