How to create folder on S3 from Ec2 instance
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
To effectively create a folder on Amazon S3 from an EC2 instance, you must understand the fundamental concepts of AWS services, IAM permissions, and the AWS CLI. This article provides a comprehensive guide to help you accomplish this task.
Understanding Amazon S3 and EC2
Amazon S3 (Simple Storage Service)
Amazon S3 is an object storage service that provides a simple web services interface to store and retrieve any amount of data from anywhere on the web. Objects in S3 are grouped in containers called buckets.
Amazon EC2 (Elastic Compute Cloud)
Amazon EC2 provides scalable computing capacity in the AWS cloud. Using EC2, you can launch instances with various configurations and manage them remotely.
Prerequisites
- AWS Account: Ensure you have an active AWS account.
- Amazon EC2 Instance: An EC2 instance with IAM roles allowing S3 access.
- AWS CLI: The AWS Command Line Interface (CLI) must be installed and configured on the EC2 instance.
- Internet Connectivity: The EC2 instance needs internet access to communicate with S3.
Setting Up IAM Roles for EC2
To allow your EC2 instance to interact with S3, it needs permissions granted through IAM roles. This procedure involves creating an IAM role and attaching it to your instance.
- Create IAM Role:
- Go to the IAM section in the AWS Management Console.
- Navigate to "Roles" and select "Create role."
- Choose "AWS service" as the type of trusted entity.
- Under “Use case,” select "EC2."
- Attach the policy "AmazonS3FullAccess" or a custom policy with suitable permissions.
- Name your role and save.
- Attach IAM Role to EC2:
- Go to the EC2 console.
- Select your instance, choose "Actions," then "Security," followed by "Modify IAM role."
- Attach your newly created IAM role.
Installing and Configuring AWS CLI
- Install AWS CLI:
- IAM Policies: When using IAM policies, it’s crucial to follow the principle of least privilege. Grant only necessary permissions.
- Security: Ensure that your EC2 instance and S3 bucket policies do not expose sensitive data. Enforce encryption and access controls where relevant.
- Efficiency: Automate these steps using scripts or cloud configuration management tools like AWS CloudFormation for repeated deployments.
Related reading
- How to create folder or key on s3 using AWS SDK for Node.js?
- How to create Kubernetes Namespace if it does not Exist?
- How to create multinode kubernetes clusters
- How to create on demand instances?
- How to create variable number of EC2 instance resources in Cloudformation template?
- How to deal with persistent storage (e.g. databases) in Docker
- How to define a service label for a kubernetes service running on GKE
- How to define external ip for kubernetes ingress

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.