Skip to content

Commit 9f10f42

Browse files
committed
R2024b release!
1 parent 56add33 commit 9f10f42

File tree

10 files changed

+6402
-8851
lines changed

10 files changed

+6402
-8851
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The files in this GitHub repository refer to commercial software products and se
44

55
The following license terms apply only to the files in this GitHub repository, including files in this folder and its subfolders, and do not apply to MathWorks Programs. References to “software” and “code” in the following license terms refer to the files in this GitHub repository.
66

7-
Copyright (c) 2020-2024, The MathWorks, Inc.
7+
Copyright (c) 2020-2025, The MathWorks, Inc.
88

99
All rights reserved.
1010

README.md

+19-17
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,24 @@ You need:
2020
You are responsible for the cost of the AWS services used when you create cloud resources using this guide. Resource settings, such as instance type, affect the cost of deployment. For cost estimates, see the pricing pages for each AWS service you will be using. Prices are subject to change.
2121

2222
# Deployment Steps
23-
By default, the MATLAB reference architectures below launch prebuilt machine images, described in [Architecture and Resources](#architecture-and-resources). Using a prebuilt machine image is the easiest way to deploy a MATLAB reference architecture. Alternatively, to build your own machine image with MATLAB using our build scripts, see [Build and Deploy Your Own Machine Image](#build-and-deploy-your-own-machine-image).
23+
By default, the MATLAB reference architectures below launch prebuilt machine images, described in [Architecture and Resources](#architecture-and-resources). Using a prebuilt machine image is the easiest way to deploy a MATLAB reference architecture.
24+
Prebuilt images are provided for the five most recent MATLAB releases.
25+
Alternatively, to build your own machine image,
26+
see [Build and Deploy Your Own Machine Image](#build-and-deploy-your-own-machine-image).
27+
You can also use this workflow to install an earlier MATLAB release.
2428

2529
## Deploy Prebuilt Machine Image
2630

2731
To view instructions for deploying the MATLAB reference architecture, select a MATLAB release:
2832

29-
| Linux | Windows |
30-
| ----- | ------- |
31-
| [R2024b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2024b/README.md) | [R2024b](releases/R2024b/README.md) |
32-
| [R2024a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2024a/README.md) | [R2024a](releases/R2024a/README.md) |
33-
| [R2023b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2023b/README.md) | [R2023b](releases/R2023b/README.md) |
34-
| [R2023a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2023a/README.md) | [R2023a](releases/R2023a/README.md) |
35-
| [R2022b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2022b/README.md) | [R2022b](releases/R2022b/README.md) |
36-
| [R2022a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2022a/README.md) | [R2022a](releases/R2022a/README.md) |
37-
| [R2021b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2021b/README.md) | [R2021b](releases/R2021b/README.md) |
38-
| [R2021a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2021a/README.md) | [R2021a](releases/R2021a/README.md) |
39-
| [R2020b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2020b/README.md) | [R2020b](releases/R2020b/README.md) |
40-
| [R2020a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2020a/README.md) | |
41-
| [R2019b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2019b/README.md) | |
42-
| [R2019a\_and\_older](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2019a_and_older/README.md) | |
43-
33+
| Linux | Windows | Status |
34+
| ----- | ------- | ------- |
35+
| [R2024b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2024b/README.md) | [R2024b](releases/R2024b/README.md) | ✅ Prebuilt available. |
36+
| [R2024a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2024a/README.md) | [R2024a](releases/R2024a/README.md) | ✅ Prebuilt available. |
37+
| [R2023b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2023b/README.md) | [R2023b](releases/R2023b/README.md) | ✅ Prebuilt available. |
38+
| [R2023a](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2023a/README.md) | [R2023a](releases/R2023a/README.md) | ⚠️ Prebuilt will be removed in September 2025. |
39+
| [R2022b](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/releases/R2022b/README.md) | [R2022b](releases/R2022b/README.md) | ⚠️ Prebuilt will be removed in March 2025. |
40+
| [Earlier/Custom](https://github.com/mathworks-ref-arch/matlab-on-aws/tree/master/packer/v1) | [Earlier/Custom](./packer/v1) | For earlier MATLAB releases, you must build your own machine image. |
4441

4542
The above instructions allow you to launch instances based on the latest MathWorks® Amazon Machine Images (AMIs).
4643
MathWorks periodically replaces older AMIs with new images.
@@ -50,6 +47,11 @@ For more details, see
5047
## Build and Deploy Your Own Machine Image
5148
For details of the scripts which form the basis of the MathWorks Windows AMI build process, see [Build Your Own Machine Image](./packer/v1). You can use these scripts to build your own custom Windows machine image for running MATLAB on Amazon Web Services. You can then deploy this custom image with the MathWorks infrastructure as code (IaC) templates.
5249

50+
You can customize the MATLAB release which is installed as part of this custom build.
51+
This includes MATLAB releases supported by the prebuilt images, as well as earlier MATLAB releases.
52+
For more details,
53+
see [Customize MATLAB Release to Install](./packer/v1#customize-matlab-release-to-install).
54+
5355
Platform engineering teams can use these scripts to take advantage of optimizations MathWorks has developed for running MathWorks products in the cloud. For more details, see [What are the advantages of building images with MathWorks scripts?](#what-are-the-advantages-of-building-images-with-mathworks-scripts)
5456

5557
## Learn about Architecture
@@ -140,6 +142,6 @@ To request assistance or additional features, contact [MathWorks Technical Suppo
140142

141143
----
142144

143-
Copyright 2018-2024 The MathWorks, Inc.
145+
Copyright 2018-2025 The MathWorks, Inc.
144146

145147
----

packer/v1/build/Install-MATLAB.ps1

+21-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md
77
88
.NOTES
9-
Copyright 2020-2024 The MathWorks, Inc.
9+
Copyright 2020-2025 The MathWorks, Inc.
1010
The function sets $ErrorActionPreference to 'Stop' to ensure that any errors encountered during the installation process will cause the script to stop and throw an error.
1111
#>
1212

@@ -48,17 +48,30 @@ function Install-MATLABUsingMPM {
4848
$DocFlag
4949
}
5050
else {
51-
aws s3 cp $SourceURL "$Env:TEMP\matlab.zip"
52-
Expand-Archive -Path "$Env:TEMP\matlab.zip" -DestinationPath $Env:TEMP\matlab_source -Force
53-
Remove-Item -Path "$Env:TEMP\matlab.zip"
51+
# Dot-sourcing the Mount-DataDriveUtils script
52+
. 'C:\Windows\Temp\config\matlab\Mount-DataDriveUtils.ps1'
53+
54+
# Setup extra volume to mount drive containing MATLAB source files
55+
$MATLABSourceDrive = 'X'
56+
$MATLABSourcePath = 'X:\matlab_source'
57+
58+
Mount-DataDrive -DriveToMount "$MATLABSourceDrive"
59+
Get-MATLABSourceFiles -SourceURL $SourceURL -Destination "$MATLABSourcePath"
60+
61+
# The source path must contain an archives folder that mpm uses for installation
62+
$SourcePath = Get-ChildItem -Path "$MATLABSourcePath" -Directory -Recurse -Filter 'archives' | Select-Object -First 1 -ExpandProperty FullName
63+
64+
if (-not $SourcePath) {
65+
throw 'Failed to find MATLAB source files at the specified location'
66+
}
67+
5468
& "$Env:TEMP\mpm.exe" install `
55-
--source=$Env:TEMP\matlab_source\dvd\archives `
69+
--source=$SourcePath `
5670
--products $ProductsList `
5771
$DocFlag
5872

59-
# Save MATLAB VersionInfo file to use with SPKG installation later
60-
Copy-Item -Path "$Env:TEMP\matlab_source\dvd\VersionInfo.xml" -Destination "$Env:ProgramData\MathWorks"
61-
Remove-Item -Path "$Env:TEMP\matlab_source" -Recurse -Force
73+
Dismount-DataDrive -DriveLetter "$MATLABSourceDrive"
74+
6275
}
6376
}
6477
catch {

packer/v1/build/Install-MATLABSupportPackages.ps1

+20-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
https://github.com/mathworks-ref-arch/matlab-dockerfile/blob/main/MPM.md
77
88
.NOTES
9-
Copyright 2024 The MathWorks, Inc.
9+
Copyright 2024-2025 The MathWorks, Inc.
1010
The function sets $ErrorActionPreference to 'Stop' to ensure that any errors encountered during the installation process will cause the script to stop and throw an error.
1111
#>
1212

@@ -43,16 +43,29 @@ function Install-MATLABSPKGUsingMPM {
4343
--products $ProductsList
4444
}
4545
else {
46-
aws s3 cp $SourceURL "$Env:TEMP\spkg.zip"
47-
Expand-Archive -Path "$Env:TEMP\spkg.zip" -DestinationPath $Env:TEMP\spkg_source -Force
48-
Move-Item -Path "$Env:ProgramData\MathWorks\VersionInfo.xml" -Destination "$Env:TEMP\spkg_source"
49-
Remove-Item -Path "$Env:TEMP\spkg.zip"
46+
# Dot-sourcing the Mount-DataDriveUtils script
47+
. 'C:\Windows\Temp\config\matlab\Mount-DataDriveUtils.ps1'
48+
49+
# Setup extra volume to mount drive containing MATLAB Support Packages source files
50+
$SpkgSourceDrive = 'X'
51+
$SpkgSourcePath = 'X:\spkg_source'
52+
53+
Mount-DataDrive -DriveToMount "$SpkgSourceDrive"
54+
Get-MATLABSourceFiles -SourceURL $SourceURL -Destination "$SpkgSourcePath"
55+
56+
Copy-Item -Path "$Env:ProgramFiles\MATLAB\${Release}\VersionInfo.xml" -Destination "$SpkgSourcePath"
57+
58+
$SourcePath = Get-ChildItem -Path "$SpkgSourcePath" -Directory -Recurse -Filter 'archives' | Select-Object -First 1 -ExpandProperty FullName
59+
60+
if (-not $SourcePath) {
61+
throw 'Failed to find MATLAB source files at the specified location'
62+
}
5063

5164
& "$Env:TEMP\mpm.exe" install `
52-
--source=$Env:TEMP\spkg_source\archives `
65+
--source=$SourcePath `
5366
--products $ProductsList
5467

55-
Remove-Item -Path $Env:TEMP\spkg_source -Recurse -Force
68+
Dismount-DataDrive -DriveLetter "$SpkgSourceDrive"
5669
}
5770
}
5871
catch {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
# Copyright 2025 The MathWorks, Inc.
2+
function Get-IMDSV2Token {
3+
<#
4+
.SYNOPSIS
5+
Retrieves an IMDSv2 token from the EC2 instance metadata service.
6+
7+
.DESCRIPTION
8+
This function sends a request to the EC2 instance metadata service to obtain an IMDSv2 token.
9+
The token is used for subsequent requests to retrieve instance metadata.
10+
11+
.PARAMETER TokenDuration
12+
The desired duration of the token in seconds.
13+
14+
.RETURNS
15+
Returns the IMDSv2 token as a string.
16+
17+
.EXAMPLE
18+
$token = Get-IMDSV2Token -TokenDuration 300
19+
#>
20+
param (
21+
[string]$TokenDuration
22+
)
23+
$Token = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token-ttl-seconds" = "$TokenDuration"} -Method Put -Uri "http://169.254.169.254/latest/api/token"
24+
return $Token
25+
}
26+
27+
function Get-MATLABSourceFiles {
28+
<#
29+
.SYNOPSIS
30+
Downloads MATLAB source files from an S3 URL and extracts them to a specified destination.
31+
32+
.PARAMETER SourceUrl
33+
The S3 URL of the zip file containing MATLAB source files.
34+
35+
.PARAMETER Destination
36+
The local directory where the source files will be extracted.
37+
38+
.EXAMPLE
39+
Get-MATLABSourceFiles -SourceUrl "s3://mybucket/matlab-source.zip" -Destination "C:\MATLABSource"
40+
#>
41+
param (
42+
[string]$SourceUrl,
43+
[string]$Destination
44+
)
45+
New-Item -Path "$Destination" -ItemType Directory -Force
46+
aws s3 cp "$SourceUrl" "$Destination\source.zip"
47+
Expand-Archive -Path "$Destination\source.zip" -DestinationPath "$Destination" -Force
48+
Remove-Item -Path "$Destination\source.zip"
49+
}
50+
51+
function Wait-VolumeAttachment {
52+
<#
53+
.SYNOPSIS
54+
Waits for an EBS volume to be attached to an EC2 instance.
55+
56+
.DESCRIPTION
57+
This function polls the AWS EC2 API to check the attachment status of a specified volume to a specified instance.
58+
It continues checking until the volume is attached or the timeout is reached.
59+
60+
.PARAMETER VolumeId
61+
The ID of the EBS volume to check.
62+
63+
.PARAMETER InstanceId
64+
The ID of the EC2 instance to which the volume should be attached.
65+
66+
.PARAMETER Region
67+
The AWS region where the volume and instance are located.
68+
69+
.PARAMETER TimeoutSeconds
70+
The maximum time to wait for the attachment, in seconds. Default is 300 seconds (5 minutes).
71+
72+
.EXAMPLE
73+
Wait-VolumeAttachment -VolumeId "vol-1234567890abcdef0" -InstanceId "i-1234567890abcdef0" -Region "us-west-2"
74+
#>
75+
param (
76+
[string]$VolumeId,
77+
[string]$InstanceId,
78+
[string]$Region,
79+
[int]$TimeoutSeconds = 300
80+
)
81+
82+
$StartTime = Get-Date
83+
$EndTime = $StartTime.AddSeconds($TimeoutSeconds)
84+
85+
while ((Get-Date) -lt $EndTime) {
86+
$AttachmentStatus = $(aws ec2 describe-volumes --region $Region --volume-ids $VolumeId --query "Volumes[0].Attachments[?InstanceId=='$InstanceId'].State" --output text)
87+
if ($AttachmentStatus -eq 'attached') {
88+
return
89+
}
90+
Start-Sleep -Seconds 5
91+
}
92+
throw "Failed to attach volume $VolumeID to instance $InstanceID."
93+
}
94+
95+
function Mount-DataDrive {
96+
<#
97+
.SYNOPSIS
98+
Creates and mounts an EBS volume to an EC2 instance and assigns it a specified drive letter.
99+
100+
.DESCRIPTION
101+
This function creates a new 128GB gp3 EBS volume in the same availability zone as the EC2 instance,
102+
attaches it to the instance, initializes the disk, creates a partition, formats it with NTFS,
103+
and assigns it the specified drive letter.
104+
105+
.PARAMETER DriveToMount
106+
The drive letter to assign to the newly created and mounted volume.
107+
108+
.EXAMPLE
109+
Mount-DataDrive -DriveToMount "M"
110+
#>
111+
param (
112+
[string]$DriveToMount
113+
)
114+
115+
$IMDSToken = Get-IMDSV2Token -TokenDuration 300
116+
117+
$InstanceID = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token" = $IMDSToken} -Method Get -Uri "http://169.254.169.254/latest/meta-data/instance-id"
118+
$Region = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token" = $IMDSToken} -Method Get -Uri "http://169.254.169.254/latest/meta-data/placement/region"
119+
$AvailabilityZone = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token" = $IMDSToken} -Method Get -Uri "http://169.254.169.254/latest/meta-data/placement/availability-zone"
120+
121+
$VolumeID=$(aws ec2 create-volume --size 128 --volume-type gp3 --availability-zone $AvailabilityZone --query "VolumeId" --output text)
122+
123+
aws ec2 wait volume-available --region $Region --volume-ids $VolumeID
124+
125+
aws ec2 attach-volume --region $Region --volume-id $VolumeID --instance-id $InstanceID --device xvdf
126+
127+
# Wait for the volume to attach
128+
try {
129+
Wait-VolumeAttachment -VolumeId $VolumeID -InstanceId $InstanceID -Region $Region
130+
Write-Output "Volume $VolumeId is successfully attached to the instance $InstanceId."
131+
} catch {
132+
throw "An error occurred while waiting for the volume $VolumeID to attach to instance $InstanceID : $_"
133+
}
134+
135+
aws ec2 modify-instance-attribute --region $Region --instance-id $InstanceID --block-device-mappings '[{\"DeviceName\":\"xvdf\",\"Ebs\":{\"DeleteOnTermination\":true}}]'
136+
137+
# AWS formats the serial number of disk in the format "volXXXX"
138+
$FormattedVolumeID = $VolumeID.Replace("-", "")
139+
140+
# Find the physical disk by matching the formatted volume ID with the serial number
141+
$Disk = Get-PhysicalDisk | Where-Object {
142+
$_.SerialNumber -like "*$FormattedVolumeID*"
143+
}
144+
145+
if ($Disk) {
146+
# Get the disk number
147+
$DiskNumber = ($Disk | Get-Disk).Number
148+
Stop-Service -Name ShellHWDetection
149+
# Initialize the disk, create a Partition, and format it
150+
Initialize-Disk -Number $DiskNumber -PartitionStyle MBR -PassThru |
151+
New-Partition -DriveLetter "$DriveToMount" -UseMaximumSize |
152+
Format-Volume -FileSystem NTFS -NewFileSystemLabel "MATLAB Source Volume" -Confirm:$false
153+
154+
Start-Service -Name ShellHWDetection
155+
} else {
156+
Write-Output "No disk found with the volume ID: $FormattedVolumeID"
157+
}
158+
159+
}
160+
161+
162+
function Dismount-DataDrive {
163+
<#
164+
.SYNOPSIS
165+
Dismounts and deletes an EBS volume associated with a given drive letter.
166+
167+
.DESCRIPTION
168+
This function takes a drive letter as input, finds the corresponding EBS volume,
169+
detaches it from the EC2 instance, and then deletes the volume.
170+
171+
.PARAMETER DriveLetter
172+
The drive letter of the volume to be dismounted and deleted.
173+
174+
.EXAMPLE
175+
Dismount-DataDrive -DriveLetter "M"
176+
#>
177+
param (
178+
[string]$DriveLetter
179+
)
180+
181+
# Retrieve the serial number of the disk
182+
$Partition = Get-Partition | Where-Object { $_.DriveLetter -eq $DriveLetter }
183+
184+
# Check if there's a drive with the specified letter
185+
if (-not $Partition) {
186+
Write-Output "No drive found with the letter $DriveLetter"
187+
return
188+
}
189+
190+
$diskNumber = $Partition.DiskNumber
191+
$PhysicalDisk = Get-PhysicalDisk | Where-Object { $_.DeviceID -eq $diskNumber }
192+
$SerialNumber = $PhysicalDisk.SerialNumber
193+
194+
# AWS formats the serial number in the format "volXXXX"
195+
# Extract the volume ID from the serial number
196+
if ($SerialNumber -match "^(vol[0-9a-f]+)_") {
197+
$RawVolumeId = $matches[1]
198+
199+
# Convert to AWS format by inserting a hyphen after 'vol'
200+
$VolumeId = $RawVolumeId.Insert(3, "-")
201+
202+
Write-Output "The volume ID is: $VolumeId"
203+
} else {
204+
Write-Output "Failed to extract a volume ID from the serial number: $SerialNumber"
205+
return
206+
}
207+
208+
# Unmount the volume
209+
Set-Disk -Number $diskNumber -IsOffline $true
210+
211+
$IMDSToken = Get-IMDSV2Token -TokenDuration 300
212+
213+
# Retrieve instance metadata using IMDSv2
214+
$Region = Invoke-RestMethod -Headers @{"X-aws-ec2-metadata-token" = $IMDSToken} -Method Get -Uri "http://169.254.169.254/latest/meta-data/placement/region"
215+
216+
# Detach and delete the volume using AWS CLI
217+
try {
218+
aws ec2 detach-volume --volume-id $VolumeId --region $Region
219+
aws ec2 wait volume-available --region $Region --volume-ids $VolumeId
220+
aws ec2 delete-volume --region $Region --volume-id $VolumeId
221+
Write-Output "Successfully detached and deleted volume $VolumeId."
222+
} catch {
223+
Write-Output "Failed to detach or delete volume ${VolumeId}: $_"
224+
}
225+
}

0 commit comments

Comments
 (0)