Start an Amazon EC2 Mac instance
Learn how to start an EC2 Mac instance
About | |
---|---|
✅ AWS experience | Beginner - 100 |
⏱ Time to complete | 10 minutes |
💰 Cost to complete | $22 for 24 hours |
🧩 Prerequisites | An AWS Account |
💻 Code Sample | - none - |
📢 Feedback | Any feedback, issues, or just a 👍 / 👎 ? |
⏰ Last Updated | 2023-06-28 |
mac
instances family, and the AWS Region. Note that, at this time, OS must be linux
and Tenancy must be Dedicated Host.mac1.metal
) and Apple silicon Mac Mini, featuring M1 SoC with 8 CPU cores, 8 GPU cores, 16 GiB of memory, and a 16 core Apple Neural Engine (mac2.metal
)1
2
3
4
5
aws ec2 allocate-hosts \
--instance-type mac2.metal \
--availability-zone us-east-2b \
--quantity 1
1
2
3
4
5
6
# Response
{
"HostIds": [
"h-0fxxxxxxx90"
]
}
HostIds
as you will need it to start the EC2 instance on that host. Remember that the billing, and the 24h minimum period of lease time, start at this moment.- We can create EBS snapshots of my volumes and create Amazon Machine Image from these. It means we can capture the state of our disk, snapshot it, and create boot images to start other machines. This is particularly useful if you need a common set of tools to be available on all instances and when the installation of these tools takes a long time, for example Xcode.
- Our EC2 Mac instances are protected from unwanted network access by VPC Security Groups. It means we can control what incoming connection is authorised, on which ports and from what IP addresses.
- Speaking of networking, we can access other AWS services from macOS, using the same VPC routing mechanisms defined at network-level (NAT Gateways, PrivateLink, Site-to-Site VPN, Direct Connect, etc.)
- We can script (and therefore automate) the provisioning, de-provisioning of dedicated hosts, and the start and stop of instances. This opens the door to all sorts of automations you can implement to support your build and test pipelines.
- AWS Systems Manager agent for macOS is preinstalled on EC2 Mac instances. It means we can remotely connect, create tunnels, or send commands to be executed on the host, without having to manage credentials, SSH keys, or network access.
- the instance type. It must be the same as the one of the dedicated host. At the time of this writing, we do support
mac1.metal
for x86 Mac mini andmac2.metal
for Apple silicon Mac mini. - an (optional) SSH keyname. SSH keys are required if you want to connect over SSH to your instance. You must create a keypair on your laptop, securely keep the private part of the key pair, and upload the public part to EC2. The documentation has step by step instructions to help you with this. The doc says
Linux
, but the steps are the same for macOS. The web console may also generates a key pair for you. - the host identifier where you want to start the EC2 instance. This must be the
HostIds
parameter received from theallocate-hosts
you ran earlier. You can only start one instance on a dedicated host. - a Security Group Id. Security Groups are network filters acting like shields around your instance. If you plan to connect to your instance, you must create a Security Group that authorises incoming TCP connections to port TCP 22 from your source IP address or range of addresses. The console guides you to do so. Our documentation has you covered as well.
- an Amazon Machine Image. This is a disk snapshot containing the operating system and some AWS-specific tools and agents already installed. You can specify your own AMI if you have one (more about this in the part four of this blog series). AWS provides you with the three last major versions of macOS. It means that, at the time of this writing, you can start an EC2 Mac instance running macOS Monterey 12.4, macOS Big Sur 11.6.6, or macOS Catalina 10.15.7.
mac2.metal
instance type, and select host Tenancy and the Host we just created.1
2
3
4
5
6
aws ec2 run-instances \
--instance-type mac2.metal \
--key-name my_key \
--placement HostId=h-0fxxxxxxx90 \
--security-group-ids sg-01000000000000032 \
--image-id AWS_OR_YOUR_AMI_ID
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Response
{
"Groups": [],
"Instances": [
{
"AmiLaunchIndex": 0,
"ImageId": "ami-01xxxxbd",
"InstanceId": "i-08xxxxx5c",
"InstanceType": "mac2.metal",
"KeyName": "my_key",
"LaunchTime": "2021-11-08T16:47:39+00:00",
"Monitoring": {
"State": "disabled"
},
... redacted for brevity ....
1
2
3
4
5
6
7
8
# to stop the instance
aws ec2 stop-instances --instance-id i-08xxxxx5c
# to reboot the instance
aws ec2 reboot-instances --instance-id i-08xxxxx5c
# to terminate the instance
aws ec2 terminate-instances --instance-id i-08xxxxx5c
1
aws ec2 release-hosts --host-ids h-0fxxxxxxx90
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.