Skip to content

Provide a CloudFormation template to setup a code server running on a EC2 instance and expose via a CloudFront distribution.

License

Notifications You must be signed in to change notification settings

aws-samples/code-server-setup-with-cloudformation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
title author date
Hosting Code Server on EC2 and CloudFront Distribution
haimtran
08/08/2024

Supported Region

By default, the provided template supports the following regions.

Region CloudFront Prefix List ID
us-west-2 pl-82a045eb
us-east-1 pl-3b927c52
ap-southeast-1 pl-31a34658

To deploy in other region, you have to update the CloudFront prefix list id map. Check docs for more details how to find the CloudFront prefix list per region.

Mappings:
  CloudFrontPrefixListIdMappings:
    us-west-2:
      PrefixListId: "pl-82a045eb"
    us-east-1:
      PrefixListId: "pl-3b927c52"
    ap-southeast-1:
      PrefixListId: "pl-31a34658"
    <YOUR_SELECTED_REGION>:
      PrefixListId: <CLOUDFRONT_PREFIX_LIST_ID_FOR_THE_SELECTED_REGION>

Deploy

To deploy the stack, you can use CLI as the below command or use the AWS CloudFormation console.

aws cloudformation create-stack \
 --stack-name code-server-stack \
 --template-body file://code-server-stack.yaml \
 --capabilities CAPABILITY_NAMED_IAM

The code-server-stack.yaml stack will:

  • Create an EC2 instance and install the code server using UserData.
  • Expose the code server via a CloudFront distribution.

Code Server Configuration

You can change the following parameters by editing the code-server-stack.yaml.

You can change configuration of the code server by editting config.yaml at the below path.

/home/ec2-user/.config/code-server/config.yaml

Here is a sample content of config.yaml with authentication disabled.

bind-addr: 0.0.0.0:8080
auth: none
password: 8766aa4b66cf555763e9564d
cert: false

Access Code Server

Option 1. The code server has been exposed via a CloudFront distribution. You can find the https endpoint in the CloudFormation console output.

Option 2. Use AWS System Manager (SSM) and port forwarding to forward the code server to local host as the following command. In this case, there are prerequisites:

  • Setup aws-cli
  • Setup AWS credentials for a profile in ~/.aws/credentials
  • Replace INSTANCE_ID, PROFILE_NAME, REGION into the below command
aws ssm start-session \
--target <INSTANCE_ID> \
--document-name AWS-StartPortForwardingSessionToRemoteHost \
--parameters "{\"portNumber\":[\"8080\"],\"localPortNumber\":[\"8080\"],\"host\":[\"<CODE_SERVER_EC2_PRIVATE_IP>\"]}" \
--profile <PROFILE_NAME>\
--region <REGION>

About

Provide a CloudFormation template to setup a code server running on a EC2 instance and expose via a CloudFront distribution.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published