How do I limit the creation of EC2 instance

,

How do I create an IAM policy, so that a user can only create a max of 3 EC2 instances?

I’m quite a noob with IAM policies, I tried looking online, but could not find what I was after


Related discussions:

I don’t think this is possible, IAM actions don’t tend to get context from the existing resources. You’d probably need to request the account limits be brought *down* from the defaults if you really need this restriction. Or add a ‘gateway lambda’ that creates the instances after doing the check on existing ones, and provide the user with access only to that.

You might be able to do something like this using service catalog though I’m not 100% sure about that. Individual IAM users wouldn’t need permission to do anything in EC2 just give them access to a service catalog item you define that limits number of systems and types of systems.

Not possible out of the box; but you can code a Lambda function that is triggered on instance launches, this function would enumerate the instances created by this user, then terminate the launched instance if it’s above the set limit.

User education could go a long way here as well.

Agreed, is look to AWS Service Catalog for this

There might be a way:

Via IAM policies, do not allow users to create EC2 instances nor Auto Scaling group. Then create an autoscaling group which controls the number of EC2s (and it supports an upper limit).

Drawback: all EC2 instances would have the same config.