macos-instance/README.md

143 lines
5.7 KiB
Markdown
Raw Permalink Normal View History

2024-11-11 21:39:42 +00:00
# EC2 Mac OS Instances
2024-11-11 21:29:09 +00:00
2024-11-11 21:39:42 +00:00
[Amazon EC2 Mac Instances](https://aws.amazon.com/ec2/instance-types/mac/)
[User Guide](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-mac-instances.html)
## Initialize instance
EC2 macOS Init is the launch daemon used to initialize Mac instances within EC2.
[ec2-macos-init](https://github.com/aws/ec2-macos-init)
2024-11-11 21:29:09 +00:00
2024-11-11 21:36:05 +00:00
## Considerations
[Read More](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-mac-instances.html#mac-instance-considerations)
Mac instances are available only as bare metal instances on Dedicated Hosts, with a minimum allocation period of 24 hours before you can release the Dedicated Host. You can launch one Mac instance per Dedicated Host. You can share the Dedicated Host with the AWS accounts or organizational units within your AWS organization, or the entire AWS organization.
## Wait time
After you launch a Mac instance, you'll need to wait until the instance is ready before you can connect to it. For an AWS vended AMI with a x86 Mac instance or a Apple silicon Mac instance, the launch time can range from approximately 6 minutes to 20 minutes. Depending on the chosen Amazon EBS volume sizes, the inclusion of additional scripts to user data, or additional loaded software on a custom macOS AMI, the launch time might increase.
You can use a small shell script, like the one below, to poll the describe-instance-status API to know when the instance is ready to be connected to. In the following command, replace the example instance ID with your own.
```shell
for i in $(seq 1 200); do aws ec2 describe-instance-status --instance-ids=i-0123456789example \
--query='InstanceStatuses[0].InstanceStatus.Status'; sleep 5; done;
```
### Updating Apple silicon Mac instances
[Read More](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mac-instance-updates.html#mac2)
2024-11-11 21:29:09 +00:00
macOS Mojave (version 10.14) (x86 Mac instances only)
macOS Catalina (version 10.15) (x86 Mac instances only)
macOS Big Sur (version 11) (x86 and M1 Mac instances)
macOS Monterey (version 12) (x86 and M1 Mac instances)
macOS Ventura (version 13) (all Mac instances, M2 and M2 Pro Mac instances support macOS Ventura version 13.2 or later)
macOS Sonoma (version 14) (all Mac instances)
macOS Sequoia (version 15) (all Mac instances)
https://aws.amazon.com/blogs/compute/building-amazon-machine-images-amis-for-ec2-mac-instances-with-packer/
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/macos-ami-overview.html
## Install Apple Remote Desktop
# NB: These commands are when using SSH to connect, when connected with SSM, switch to ec2-user first with 'su -c ec2-user'
# set a password to ec2-user
sudo passwd ec2-user
# enable ARD
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart \
-activate -configure -access -on \
-restart -agent -privs -all
## SSM Tunnels to connect to Apple Remote Desktop
```shell
# first, select the instance ID of the machine you want to connect
# the below command search for a machine named "macOS Monterey"
INSTANCE_ID=$(aws ec2 describe-instances \
--filter "Name=tag:Name,Values=macOS Monterey" \
--query "Reservations[].Instances[?State.Name == 'running'].InstanceId[]" \
--output text)
# second, start the SSM tunnel
aws ssm start-session --target $INSTANCE_ID \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["5900"],"localPortNumber":["5900"]}'
Starting session with SessionId: sst-0f3b970f24182795d
Port 5900 opened for sessionId sst-0f3b970f24182795d.
Waiting for connections...
```
## Connect w/ssh and tunnel VNC ports
# We assume the EC2 Mac instance public IP address is 1.0.0.0
ssh -C -N -L 5900:localhost:5900 -i /path/my-key-pair.pem ec2-user@1.0.0.0
## Changing resolution
```shell
# install the displaylist command line tool
brew tap jakehilborn/jakehilborn && brew install displayplacer
# then list available resolutions
displayplacer list
Persistent screen id: 69784AF1-CD7D-B79B-E5D4-60D937407F68
Contextual screen id: 1020887298
Type: 24 inch external screen
Resolution: 1024x768
Hertz: 60
Color Depth: 8
Scaling:off
Origin: (0,0) - main display
Rotation: 0
Resolutions for rotation 0:
mode 0: res:1024x768 hz:60 color_depth:4
mode 1: res:1024x768 hz:60 color_depth:8 <-- current mode
mode 2: res:640x480 hz:60 color_depth:4
mode 3: res:640x480 hz:60 color_depth:8
mode 4: res:720x480 hz:60 color_depth:4
mode 5: res:720x480 hz:60 color_depth:8
mode 6: res:640x480 hz:60 color_depth:4
mode 7: res:640x480 hz:60 color_depth:8
mode 8: res:800x600 hz:60 color_depth:4
mode 9: res:800x600 hz:60 color_depth:8
mode 10: res:1280x720 hz:60 color_depth:4
mode 11: res:1280x720 hz:60 color_depth:8
mode 12: res:1440x900 hz:60 color_depth:4
mode 13: res:1440x900 hz:60 color_depth:8
mode 14: res:1680x1050 hz:60 color_depth:4
mode 15: res:1680x1050 hz:60 color_depth:8
mode 16: res:1920x1080 hz:60 color_depth:4
mode 17: res:1920x1080 hz:60 color_depth:8
mode 18: res:1920x1200 hz:60 color_depth:4
mode 19: res:1920x1200 hz:60 color_depth:8
mode 20: res:2560x1440 hz:60 color_depth:4
mode 21: res:2560x1440 hz:60 color_depth:8
mode 22: res:2560x1600 hz:60 color_depth:4
mode 23: res:2560x1600 hz:60 color_depth:8
mode 24: res:1024x576 hz:60 color_depth:4
mode 25: res:1024x576 hz:60 color_depth:8
Execute the command below to set your screens to the current arrangement:
displayplacer "id:69784AF1-CD7D-B79B-E5D4-60D937407F68 res:1024x768 hz:60 color_depth:8 scaling:off origin:(0,0) degree:0"
# Lastly, set the display resolution. We will choose 1440x900
displayplacer "id:69784AF1-CD7D-B79B-E5D4-60D937407F68 res:1440x900 or
```