@@ -44,18 +44,62 @@ public class Ide extends Construct {
4444 private final Role lambdaRole ;
4545 private CustomResource passwordResource ;
4646
47+ /**
48+ * Architecture enum for IDE instances.
49+ * Determines instance types and AMI selection.
50+ */
51+ public enum IdeArch {
52+ ARM64 ("arm64" , "aarch64" ),
53+ X86_64 ("x86_64" , "x86_64" );
54+
55+ private final String awsValue ;
56+ private final String unameValue ;
57+
58+ IdeArch (String awsValue , String unameValue ) {
59+ this .awsValue = awsValue ;
60+ this .unameValue = unameValue ;
61+ }
62+
63+ public String getAwsValue () { return awsValue ; }
64+ public String getUnameValue () { return unameValue ; }
65+ }
66+
67+ /**
68+ * IDE type enum for selecting between code-server and AWS Code Editor.
69+ */
70+ public enum IdeType {
71+ CODE_EDITOR ("code-editor" ),
72+ VSCODE ("vscode" );
73+
74+ private final String scriptName ;
75+
76+ IdeType (String scriptName ) {
77+ this .scriptName = scriptName ;
78+ }
79+
80+ public String getScriptName () { return scriptName ; }
81+ }
82+
4783 public static class IdeProps {
4884 private String instanceName = "ide" ;
4985 private int diskSize = 50 ;
5086 private IVpc vpc ;
51- private IMachineImage machineImage = MachineImage . latestAmazonLinux2023 () ;
52- private List < String > instanceTypes = Arrays . asList ( "m7i-flex.xlarge" , "m7a.xlarge" , "m6i.xlarge" , "m6a.xlarge" , "m5.xlarge" , "t3.xlarge" ) ;
87+ private IdeArch ideArch = IdeArch . ARM64 ;
88+ private IdeType ideType = IdeType . CODE_EDITOR ;
5389 private List <ISecurityGroup > additionalSecurityGroups = new ArrayList <>();
5490 private int bootstrapTimeoutMinutes = 30 ;
5591 private String gitBranch = "main" ;
5692 private String templateType = "base" ;
5793 private Role ideRole ;
5894
95+ // Architecture-specific instance type lists
96+ private static final List <String > ARM64_INSTANCE_TYPES =
97+ Arrays .asList ("m7g.xlarge" , "m6g.xlarge" , "c7g.xlarge" , "t4g.xlarge" );
98+ private static final List <String > X86_64_INSTANCE_TYPES =
99+ Arrays .asList ("m7i-flex.xlarge" , "m7a.xlarge" , "m6i.xlarge" , "m6a.xlarge" , "m5.xlarge" , "t3.xlarge" );
100+ // Old instance list (x86_64) for reference:
101+ // Arrays.asList("m7i-flex.xlarge", "m7a.xlarge", "m6i.xlarge", "m6a.xlarge", "m5.xlarge", "t3.xlarge");
102+
59103 public static IdeProps .Builder builder () { return new Builder (); }
60104
61105 public static class Builder {
@@ -64,8 +108,8 @@ public static class Builder {
64108 public Builder instanceName (String instanceName ) { props .instanceName = instanceName ; return this ; }
65109 public Builder diskSize (int diskSize ) { props .diskSize = diskSize ; return this ; }
66110 public Builder vpc (IVpc vpc ) { props .vpc = vpc ; return this ; }
67- public Builder machineImage ( IMachineImage machineImage ) { props .machineImage = machineImage ; return this ; }
68- public Builder instanceTypes ( List < String > instanceTypes ) { props .instanceTypes = instanceTypes ; return this ; }
111+ public Builder ideArch ( IdeArch ideArch ) { props .ideArch = ideArch ; return this ; }
112+ public Builder ideType ( IdeType ideType ) { props .ideType = ideType ; return this ; }
69113 public Builder additionalSecurityGroups (List <ISecurityGroup > additionalSecurityGroups ) { props .additionalSecurityGroups = additionalSecurityGroups ; return this ; }
70114 public Builder bootstrapTimeoutMinutes (int bootstrapTimeoutMinutes ) { props .bootstrapTimeoutMinutes = bootstrapTimeoutMinutes ; return this ; }
71115 public Builder gitBranch (String gitBranch ) { props .gitBranch = gitBranch ; return this ; }
@@ -78,8 +122,20 @@ public static class Builder {
78122 public String getInstanceName () { return instanceName ; }
79123 public int getDiskSize () { return diskSize ; }
80124 public IVpc getVpc () { return vpc ; }
81- public IMachineImage getMachineImage () { return machineImage ; }
82- public List <String > getInstanceTypes () { return instanceTypes ; }
125+ public IdeArch getIdeArch () { return ideArch ; }
126+ public IdeType getIdeType () { return ideType ; }
127+
128+ public IMachineImage getMachineImage () {
129+ return ideArch == IdeArch .ARM64
130+ ? MachineImage .latestAmazonLinux2023 (AmazonLinux2023ImageSsmParameterProps .builder ()
131+ .cpuType (AmazonLinuxCpuType .ARM_64 ).build ())
132+ : MachineImage .latestAmazonLinux2023 ();
133+ }
134+
135+ public List <String > getInstanceTypes () {
136+ return ideArch == IdeArch .ARM64 ? ARM64_INSTANCE_TYPES : X86_64_INSTANCE_TYPES ;
137+ }
138+
83139 public List <ISecurityGroup > getAdditionalSecurityGroups () { return additionalSecurityGroups ; }
84140 public int getBootstrapTimeoutMinutes () { return bootstrapTimeoutMinutes ; }
85141 public String getGitBranch () { return gitBranch ; }
@@ -263,6 +319,8 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
263319 .replace ("${GIT_BRANCH}" , gitBranch )
264320 .replace ("${AWS_REGION}" , Aws .REGION )
265321 .replace ("${TEMPLATE_TYPE}" , templateType )
322+ .replace ("${ARCH}" , props .getIdeArch ().getUnameValue ())
323+ .replace ("${IDE_TYPE}" , props .getIdeType ().getScriptName ())
266324 .replace ("${WAIT_CONDITION_HANDLE_URL}" , waitHandle .getRef ());
267325
268326 userData .addCommands (userDataContent );
@@ -334,8 +392,19 @@ public Ide(final Construct scope, final String id, final IdeProps props) {
334392 .build ();
335393 waitCondition .getNode ().addDependency (ec2InstanceResource );
336394
337- var ideUrlOutput = CfnOutput .Builder .create (this , "Url" )
338- .value ("https://" + distribution .getDistributionDomainName ())
395+ // Build URL based on IDE type
396+ String ideUrl ;
397+ if (props .getIdeType () == IdeType .CODE_EDITOR ) {
398+ // Token-based URL for Code Editor (seamless Workshop Studio access)
399+ ideUrl = "https://" + distribution .getDistributionDomainName () +
400+ "/?folder=/home/ec2-user/environment&tkn=" + getIdePassword (instanceName );
401+ } else {
402+ // Standard URL for code-server (password entered via login page)
403+ ideUrl = "https://" + distribution .getDistributionDomainName ();
404+ }
405+
406+ CfnOutput .Builder .create (this , "Url" )
407+ .value (ideUrl )
339408 .description ("Workshop IDE Url" )
340409 .exportName (instanceName + "-url" )
341410 .build ();
0 commit comments