CloudFormation allows you to manage your AWS infrastructure by defining it in code. In this post, I will show you guys how to create an instance and attach an role to it so you can access your buckets. EC2 IAM S3 First, you’ll need a template that specifies the resources that you want in your stack. For this step, you use a sample that I already prepared: template The template creates a basic instance that uses an with . It also creates a security group which allows access from anywhere. EC2 IAM Role S3 List Policy SSH Note: I used also the section to declare values that can be passed to the template when you create the stack. Parameters Now we defined the template. Sign in to then navigate to , and click on “ “. Upload the file: AWS Management Console CloudFormation Create Stack JSON You would be asked to assign a name to this stack, and choose your EC2 specs configuration & SSH KeyPair: Make sure to check the box “ ” in order to create the & : I ackownledge the AWS CloudFormation might create IAM resources IAM Policy Role Once launched, you will get the following screen with launching process events: After a while, you will get the message in the status tab: CREATE_COMPLETE Once done, on the output tab, you should see how to connect via to your instance: SSH If you point your terminal to the value shown in the output tab, you should be able to connect via SSH to server: |ssh ec2-user@52.91.239.135 -i vpc.pem Let’s check if we can list the S3 buckets using the : AWS CLI |aws s3 ls Awesome ! so we are able to list the buckets, but what if we want to create a new bucket: It didn’t work, and it’s normal because the attached to the instance doesn’t have enough permission ( action). IAM Role CreateBucket