CDK Construct for a VSCode Server development environment on EC2
Project description
CDK VSCode Server Construct
This is a CDK Construct for creating a VSCode server on an Amazon Linux EC2 instance.
You can easily access Visual Studio Code Server through your browser and start development.
In the EC2 security group's inbound rules, communication from the Internet is not allowed, ensuring secure access to the VSCode server. Additionally, by passing the IAM policy to be attached to the EC2 instance as a property, you can grant appropriate permissions for AWS access within VSCode.
Usage
Install the package:
npm install cdk-code-server
Use it in your CDK stack:
import { CodeServer } from 'cdk-code-server';
new CodeServer(this, 'CodeServer');
You can customize the instance type, vpc, and other properties:
import { CodeServer } from 'cdk-code-server';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
// Use an existing VPC
declare const vpc: ec2.IVpc;
// Use an existing policy as a instance role
declare const policy: iam.PolicyStatememnt;
new CodeServer(this, 'CodeServer', {
vpc,
// Specify the instance type
// Default is c7g.2xlarge
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MEDIUM),
// Specify the CPU architecture
// Default is ec2.AmazonLinuxCpuType.ARM_64
cpuType: ec2.AmazonLinuxCpuType.X86_64,
// Specify the IAM policy for the instance role
// Default is a policy that has an administrator access
policy,
// Specify the size of the EBS volume
// Default is 30 GB
volumeSize: 100,
});
Setup VSCode Server
After the stack is deployed, you can access the server via AWS Systems Manager (SSM) Session Manager by default and start the VSCode server:
Access to the EC2 instance (Default: SSM)
- In the AWS Console, go to the EC2 Instances page and select your instance.
- Click the "Connect" button, choose "Session Manager", and click "Connect".
- Once connected, switch to the ec2-user account:
sudo su --login ec2-user
Start the VSCode server
Execute the following command to start the VSCode server:
[ec2-user@ip-10-0-0-23 ~]$ code tunnel service install
[2024-06-10 02:10:42] info Using GitHub for authentication, run `code tunnel user login --provider <provider>` option to change this.
To grant access to the server, please log into https://github.com/login/device and use code 3811-9932
Next, open your browser and go to https://github.com/login/device, enter the code, and complete the authentication.
In the example above, enter '3811-9932' > Continue > Continue > Authorize-Visual-Studio-Code.
Return to the EC2 instance, run the code tunnel again, and open the displayed URL https://vscode.dev/tunnel/ip-{privateIp}{region} in your browser.
[ec2-user@ip-10-0-0-23 ~]$ code tunnel
*
* Visual Studio Code Server
*
* By using the software, you agree to
* the Visual Studio Code Server License Terms (https://aka.ms/vscode-server-license) and
* the Microsoft Privacy Statement (https://privacy.microsoft.com/en-US/privacystatement).
*
[2024-06-10 02:11:44] info Creating tunnel with the name: ip-10-0-0-23ap-north
[2024-06-10 02:11:44] info Open this link in your browser https://vscode.dev/tunnel/ip-10-0-0-23ap-north
Connected to an existing tunnel process running on this machine.
Open this link in your browser https://vscode.dev/tunnel/ip-10-0-0-23ap-north
VSCode will open, and you'll be prompted with "What type of account did you use to start this tunnel?" Select GitHub.
At this point, the GitHub authentication screen may appear again, so press Authorize.
Once you open the terminal, you’re all set.
(Option) Access via EC2 Instance Connect Endpoint (EIC Endpoint)
If the useInstanceConnectEndpoint option is set to true, you can connect via the EC2 Instance Connect Endpoint.
- In the AWS Console, go to the EC2 Instances page and select your instance.
- Click the "Connect" button, choose "EC2 Instance Connect", then select "Connect using EC2 Instance Connect Endpoint", and click "Connect".
- Once connected, you will see a screen similar to the following:
- Follow the same steps as in the SSM section to start the VSCode server and connect via tunnel.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdk_code_server-1.0.3.tar.gz.
File metadata
- Download URL: cdk_code_server-1.0.3.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d398fa5689eccdcce019617d672e156919d97cc7eeb496d56af6eef538df760
|
|
| MD5 |
3a1c3c1bbc70cabce51c99754716a5d9
|
|
| BLAKE2b-256 |
81b87d21dd66702cf2408f4ae504075b26608f5481f47f47568d6fd0336bd830
|
Provenance
The following attestation bundles were made for cdk_code_server-1.0.3.tar.gz:
Publisher:
release.yml on badmintoncryer/cdk-code-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdk_code_server-1.0.3.tar.gz -
Subject digest:
8d398fa5689eccdcce019617d672e156919d97cc7eeb496d56af6eef538df760 - Sigstore transparency entry: 516992852
- Sigstore integration time:
-
Permalink:
badmintoncryer/cdk-code-server@1c038a2c21d0dc9196c7fed65edf987cf9474f66 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/badmintoncryer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1c038a2c21d0dc9196c7fed65edf987cf9474f66 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cdk_code_server-1.0.3-py3-none-any.whl.
File metadata
- Download URL: cdk_code_server-1.0.3-py3-none-any.whl
- Upload date:
- Size: 1.3 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5efdfad9645df34d84ed8d45d09365849ef893a41865f4bb882364acfacfc1df
|
|
| MD5 |
593af019d1fc91432f854d94eec1cd69
|
|
| BLAKE2b-256 |
2ba1ffb9878013d14c8dddf5e1a1cdc7de7a6fc5a7e771179b75fb2bdcb89534
|
Provenance
The following attestation bundles were made for cdk_code_server-1.0.3-py3-none-any.whl:
Publisher:
release.yml on badmintoncryer/cdk-code-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cdk_code_server-1.0.3-py3-none-any.whl -
Subject digest:
5efdfad9645df34d84ed8d45d09365849ef893a41865f4bb882364acfacfc1df - Sigstore transparency entry: 516992818
- Sigstore integration time:
-
Permalink:
badmintoncryer/cdk-code-server@1c038a2c21d0dc9196c7fed65edf987cf9474f66 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/badmintoncryer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1c038a2c21d0dc9196c7fed65edf987cf9474f66 -
Trigger Event:
push
-
Statement type: