Unable to create instances with encrypted root volume from AWS Tools for PowerShell or CLI?

We do not have EBS Volume encryption enabled by default and that’s not something we can do at this time. However, we would like the majority of our new instances created with encryption for all volumes using the default EBS key.

This works fine using the console, but that’s not useful for partial automation (meaning, I’m not looking for Terraform, Ansible or other solutions at this point).

Our preferred method is PowerShell, but I’ve been unable to launch an Instance with an encrypted volume using the CLI either following the example here:

How to quickly launch encrypted EBS-backed EC2 instances from unencrypted AMIs | AWS Security Blog (amazon.com)

The only change I’ve made to the ‘mapping.json’ file in the example is to remove the KMS Key ID, which should set it to use the default key according to the blog post. I can launch an instance without encryption successfully after running that with an updated AMI ID and valid Security Group, SSH Key, etc.

If I try to launch it with Encryption, the instance will launch and then immediately terminate itself. This is the behaviour in both AWS CLI and PowerShell.

Has anyone else run into this and solved it, or know what the solution is here compared to the blog post?

EDIT - thank you everyone for the suggestions and direction. It turned out to be caused by a policy enforcing MFA access, which allows the user to reset their password and enable MFA before any other AWS services are allowed. My IAM has MFA enabled for the console and has not had an issue with any other API operation until this one with KMS. I don’t have a solution for that yet, but at least the main blocker has been figured out.

Pretty sure the role associated with the instance profile needs the permission to use your kms key

So far I’m not using a role on the instance, just my IAM account which has the necessary permissions to run the CLI command.

This screams of “you don’t have permission to the key”, I’ve seen this over a dozen times. Double check Cloudtrail and your IAM permissions.

That’s what I’m saying. You are gonna have to make an instance profile that uses a role with permission to use that kms key. Search “iam role encrypt root volume” on Google and you should be able to find info on it.

The ec2 won’t stablized until it can use the kms you are instructing it to use through its instance profile

Hm, ok thanks, I’ll search for that. It’s a bit surprising in that I can use the console to create them encrypted with no issues with that IAM account.

Exactly this. To confirm, you need to check the permissions of the IAM user or role which you have configured in powershell needs to have permissions. Below link explains it quite well, and highlights what permissions you need
https://aws.amazon.com/premiumsupport/knowledge-center/encrypted-volumes-stops-immediately/

I’m not getting any errors in CloudTrail - the instance is launching successfully and I see that in CloudTrail with no errors in the log, but then immediately terminates. I don’t see any CloudTrail message for that part.

Thanks, I’ll read through that link. I didn’t come across that in my searches (different search terms).

What’s the termination reason in the console?

‘Client.InternalError: Client error on launch’

Which from the docs suggests a KMS permissions error. What I’m having trouble now with is how to set the permissions since this is an AWS managed key.

Troubleshoot instance launch issues - Amazon Elastic Compute Cloud

I gave my IAM user full access to KMS after first giving it a more limited scope, but I’m still getting the error and result.

There isn’t a way to edit the policy directly on the AWS managed KMS key.

check this if it helps → the key you are using to encrypt the volume also require permissions to use the key, the IAM user used in your powershell script or whatever your method of launch is should have permission to use the key.

The default key has permissions for all EBS users in the AWS account, I don’t think you need to edit this key or can edit this key.

-------------------

“Sid”: “Allow access through EBS for all principals in the account that are authorized to use EBS”,

“Effect”: “Allow”,

“Principal”: {

“AWS”: “*”

},

-------------------

Right, can’t edit it. The policy on it would suggest I have permission to use it already; I tried adding ‘ec2:*’ and ‘ebs:*’ to my IAM account policies with no change.

So you’re suprised that you as a console userv identity can have permissions to a Kms resource but that your instance, with a totally different identity does not? What user, i.e. instance profile, would you expect or prefer these instances to be using?