IAM Shenanigans

post-cover

After moving my blog to AWS, the next step for me was to try interacting with S3 programmatically. I am currently building a portfolio builder app in Elixir, and like so many other web apps out there, it involves storage of static files uploaded by the user. So, I used this as another opportunity to get in more contact with S3 as one of the most common AWS services, but more importantly, I got more familiar with IAM concepts and best practices.

So, this article describes the IAM setup I had for this goal. Keep in mind that this setup was done for development purposes on my local machine, which means I had freedom to explore without worrying about loose permissions at first. It also means that the final setup would be slightly different in production when I deploy the app on an EC2 instance.

Initial Implementation

I always like to start small and rough with only one goal: make it work. So, I created a bucket, wrote some back-end logic to interact with it, then I configured the client SDK (ExAws) to authenticate using my own access keys. It worked fine and was very straightforward to set up. However, there are multiple problems with this approach:

But overall this was a successful attempt at making it work. Next step is to make it right.

Current Implementation

There are multiple things that needed to be done in order to restrict the permissions and follow best practices. This diagram explains the current state of authentication/authorization flow between my app and the S3 bucket after all changes have been made.

IAM Flow

The details, starting from the S3 bucket, are as follows:

As someone getting started with AWS, it wasn’t a straightforward task to grasp all these concepts enough to arrange them in my head and in a diagram like the one above, much less applying them. Luckily, with enough time of reading the documentation, AI prompting, asking around for help, and letting it all marinate in my head, I was able to put the pieces together.

Lessons Learned

Despite the end goal simple being object handling in an S3 bucket, the bulk of what I learned in this endeavor has been IAM, and that is why it has been the focus of this article. I got a better understanding of concepts like roles, policies, Identity Center, organizations, and applying least-principle permissions. Also, the recurring theme of my AWS learning (apart from drawing diagrams) is how fascinating it is that platform-as-a-service companies managed to wrap all of this under a couple of button clicks.

Overall, I believe this has been one of the essential parts to learn in AWS because surely no resources can be accessed without the correct permissions in place. So, I will be looking forward to applying this in future projects.