Simplified Access: Using AWS Session Manager for EC2 without a PEM File
Published: 2024-01-25 22:16:16

In this post, we'll explore how to utilise AWS Session Manager to access an EC2 instance without the need for a PEM file.

---

**Create IAM Role**

Before diving into the creation of an EC2 instance, it's essential to set up an IAM (Identity and Access Management) role. IAM roles help in securely granting permissions that your EC2 instance will need.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h5e8davn2ufairsy4hpb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xvosjg9wepl0dhzrlqwl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/659umc6ofdiiaikjoibm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yaxg6gx0lhh68y0ojucf.png)

- Navigate to the IAM dashboard in your AWS console.
- Create a new role and attach the `AWSSSMManagedInstanceCore` policy to it.

Important: Select the correct service use case. Choosing the wrong service will prevent this role from appearing when setting up your EC2 instance.

---

**Create EC2 Instance**
Now, let's create our EC2 instance

- Head over to the EC2 dashboard and click the `Launch instance` button.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tvf90p05kwniyg9fo3s.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/37ho1cpyp7djy2d114n8.png)

- In the network settings, ensure `Auto-assign Public IP` is enabled. Select your desired security group.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pd8s59oyuo26va3w2ty3.png)

- Under `Advanced Details`, choose the IAM role you created earlier.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ikllmpzzgwkgw80rwx3s.png)

- Review your settings in the Summary section and then launch the instance.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xr4y0s5enx09dq5nscgi.png)
- A popup will appear since we haven't created a new key pair (PEM file). As we're using Session Manager, click on the `Proceed without key pair` option.

---

**Access an EC2 Instance via AWS Console**
Once your EC2 instance is up and running,

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf9s9j7t60b6uowjcpfh.png)
- Click on the instance ID in the EC2 dashboard.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjxs6dagou1dlvtt0l8q.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5q86boluoc6bo682itkv.png)
- Hit the `Connect` button.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p5ar2xgonxtpbtlt28cg.png)
- You can now access the EC2 instance through AWS Session Manager.

Note: In this tutorial, we've created an EC2 instance within the default VPC and assigned a public IP to it. Depending on your VPC settings, the 'Connect' button might be disabled. Make sure to verify your VPC settings if you encounter this issue.




---

You've successfully accessed an EC2 instance without a PEM file using AWS Session Manager!
Don't forget to terminate your EC2 instance once you're done.😉