Testing Lightsail Containers with Minecraft
Tags: aws, minecraft
Published: 2022-10-17 20:14:03

<!-- wp:image {"align":"center","id":684,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/lightsailcontainer.png" alt="" class="wp-image-684"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Editor's Note</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
This article was originally published on www.linuxtek.ca and some of the links and references will refer back to that site.
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Introduction</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>After my <a href="https://www.linuxtek.ca/2022/09/18/migrating-wordpress-from-gcp-to-aws/">previous article</a> where I used Amazon Lightsail to migrate my blog to an Amazon Lightsail VPS (Virtual Private Server) instance, I decided to try out the <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services">Lightsail Container Service</a> to see if it was similarly easy to use.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The use case here would be that in some cases for testing a service in a Docker container, it would be easier to deploy it on a service like Lightsail, rather than spinning up an entire environment using AWS <a href="https://aws.amazon.com/ecs/">Elastic Container Service</a>, or <a href="https://aws.amazon.com/eks">Elastic Kubernetes Service</a>.  While both of these services can use <a href="https://aws.amazon.com/fargate/">AWS Fargate</a> for serverless container workloads, there is a lot more infrastructure that needs to be built in order to run the container.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services">Amazon Lightsail Container Service</a> provides an easy way to run your containers in the cloud, and is ideal for simple workloads.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Lightsail Container Service Details</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before getting started, it's important to understand how the service is designed.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>While Lightsail provides a simplified deployment method, it's important to understand that under the hood, the service is powered by many of the other AWS services, such as <a href="https://aws.amazon.com/ec2/">Amazon Elastic Compute Cloud (Amazon EC2)</a>, <a href="https://aws.amazon.com/rds/">Amazon Relational Database Service (RDS)</a>, <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html">Application Load Balancer</a>, etc.  For more details see this <a href="https://aws.amazon.com/blogs/aws/lightsail-containers-an-easy-way-to-run-your-containers-in-the-cloud/">blog post</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Within a Lightsail Container Service, there are multiple nodes running the containers, and a load balancer.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":685,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/amazon-lightsail-container-service-diagram.png" alt="" class="wp-image-685"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The <strong>Scale</strong> and <strong>Power</strong> are both capacity parameters that can be set when creating the container service.  The scale specifies the number of compute nodes in your container service, and the power specifies the memory and vCPUs of each node in your service.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>These values can be <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-changing-container-service-capacity">changed dynamically</a> in the Lightsail console after the initial creation without any downtime, allowing to adjust for over/under-provisioning.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Running Minecraft</h2>
<!-- /wp:heading -->

<!-- wp:image {"align":"center","id":687,"width":653,"height":238,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/minecraftlogo-1024x373.png" alt="" class="wp-image-687" width="653" height="238"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Minecraft is a good test for a service like Lightsail, as it will put some stress on the service.  Althought it's not quite load testing, when logging onto a Minecraft server, you can immediately tell if the service is struggling by looking at statistics like CPU and memory usage, latency/lag, and any errors in the Minecraft console CLI.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>I've written a number of articles on how to set up Minecraft on a server, including <a href="https://www.linuxtek.ca/2022/01/30/build-a-fully-functional-minecraft-server-in-less-than-10-minutes-with-ansible/">automating the install using Ansible</a>.  For testing Minecraft as a Docker container, I will be using the <a href="https://hub.docker.com/r/itzg/minecraft-server">itzg/minecraft-server</a> Docker image, as it is already built and well maintained.  More information can be found on the <a href="https://hub.docker.com/r/itzg/minecraft-server">Docker Hub</a> page, and <a href="https://github.com/itzg/docker-minecraft-server/blob/master/README.md">Github</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Setting Up Lightsail</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In the <a href="http://console.aws.amazon.com/">AWS Console</a>, you can search the services for Lightsail, or go directly to the <a href="https://lightsail.aws.amazon.com/">Amazon Lightsail Console</a>.  Once there, click on Containers:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":688,"width":557,"height":365,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_15-48-20.png" alt="" class="wp-image-688" width="557" height="365"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Click the "Create Container Service" button, and go through the menus to set up the container service:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>Location - We will leave the default as us-east-1.</li><li>Container Service Capacity - As Minecraft needs a decent amount of RAM to run, we will choose Md (Medium) size for 2GB RAM and 1vCPU.  The Docker container will try to use 1GB for Minecraft by default, so smaller sizes would not be recommended.</li><li>Scale - Since everything is self-contained, we will only choose x1 instance to run.</li><li>Deployment - Click the <strong>+Set Up Deployment</strong> button and choose <strong>Specify a custom deployment</strong>.<ul><li>Container Name - Set this to <strong>minecraft-container</strong>.</li><li>Image - As the image is already located on Docker Hub, we can enter <strong>itzg/minecraft-server</strong> as the image to pull from the registry.</li><li>Environment Variables - As per the <strong>itzg/minecraft-server</strong> <a href="https://github.com/itzg/docker-minecraft-server/blob/master/README.md">documentation</a>, we can auto accept the EULA for Minecraft during setup by setting <code>EULA: TRUE</code>.  We will add Key = EULA, Value = TRUE to ensure this is set automatically.</li><li>Open Ports - Minecraft typically allows users to connect on TCP Port 25565, so we will open this port.  </li><li>Public Endpoint - Leave this unselected for now.  More on this later.</li><li>Under the "Identify Your Service" section, we will name the service <strong>minecraft-service</strong>.</li></ul></li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Once complete, the settings should look like this:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":703,"width":553,"height":820,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_18-45-14.png" alt="" class="wp-image-703" width="553" height="820"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Review the <strong>Summary</strong> section and be aware of the cost of the container service:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":692,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-00-52.png" alt="" class="wp-image-692"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>As we will be temporarily testing, this shouldn't incur a large monthly charge.  &nbsp;However, be aware that you are charged for your container service whether it's enabled or disabled, and whether it has a deployment or not. <strong><span style="text-decoration: underline;">You must delete your container service to stop being charged for it.</span></strong></p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Click the <strong>Create Container Service</strong> button once everything is filled out:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":691,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-02-35.png" alt="" class="wp-image-691"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>It may take a few minutes for the service and deployment to load.  Once the service is available, you can click on <strong>Deployments</strong>, and <strong>Open Log</strong> to see the progress as the container starts up:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":699,"width":754,"height":502,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-33-01-1.png" alt="" class="wp-image-699" width="754" height="502"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The <strong>Logs</strong> screen will show the progress as the Docker container is initialized, and the Minecraft server is launched:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":700,"width":754,"height":179,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full is-resized"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-57-33.png" alt="" class="wp-image-700" width="754" height="179"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Wait until the Minecraft world completes generating.  It should look like this when complete:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":705,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_17-06-35.png" alt="" class="wp-image-705"/></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Connecting to the Minecraft Server</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The Minecraft server is now running, but we haven't set a public endpoint to connect into the container service via the internet, so there is no way to connect.  Unfortunately, there is a limitation of Lightsail Containers where the public endpoint can only be HTTP or HTTPS, due to the way the Application Load Balancer is set up.  <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services#container-services-endpoints-domains">This article</a> confirms the limitation:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>The public endpoint of Lightsail container services supports HTTPS only, and it does not support TCP or UDP traffic. </code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>I did test trying to find a way around this, such as using an NGINX Reverse Proxy to stream the traffic via an open HTTP/HTTPS port to the internal port 25565.  <a href="https://github.com/vollborn/minecraft-nginx-reverse-proxy">This project</a> seemed promising and was designed for a similar function, and when tested locally, would forward the traffic on an HTTP port on to the Minecraft server and allow a client to connect.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Unfortunately the web server container would fail health checks and get terminated; since the web traffic would be passed to Minecraft, which wouldn't know how to respond.  Adding a separate active health check is a <a href="https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-health-check/">feature</a> of the paid version of NGINX - NGINX Plus. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>So unfortunately while the Minecraft server does appear to run on Lightsail Containers, we are not able to connect to the server to test with a Minecraft client.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Other Limitations</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Initially, rather than using the Amazon Lightsail web console, I wanted to define all of the infrastructure as code using Terraform.  Unfortunately, Lightsail components are not fully included in the official AWS Terraform provider.  Some of the components, such as the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_container_service">Lightsail Container Service</a> and <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lightsail_instance">Lightsail Instance</a> are available, however others such as Load Balancer resources are not currently available.  There are open <a href="https://github.com/hashicorp/terraform-provider-aws/pull/11405">Pull Requests</a> on the Hashicorp Github, but they have been sitting for a few years now.  They would need to be upvoted to increase priority.  Something to be aware of if you're looking to leverage Lightsail fully with Infrastructure-As-Code - some of the components may not be available.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The AWS CLI v2 does have a <a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lightsail/index.html">full set of commands</a> for Lightsail, which can be helpful if you don't want to use the web console.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Troubleshooting</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>When creating the Lightsail Container Service for the first time, I received this error:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":693,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-full"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-07-58.png" alt="" class="wp-image-693"/></figure>
<!-- /wp:image -->

<!-- wp:code -->
<pre class="wp-block-code"><code>CreateContainerService&#91;us-east-1]
Sorry, you've either reached or will exceed your maximum limit of Lightsail Container Services.</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>This was puzzling because I didn't have any other Lightsail Container Services active.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Checking in the <strong>Service Quotas</strong> section in AWS, the quotas for Amazon Lightsail appear to have enough capacity by default to allow the service creation, although the Lightsail quotas cannot apparently be changed or increases requested.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"align":"center","id":694,"sizeSlug":"large","linkDestination":"none"} -->
<figure class="wp-block-image aligncenter size-large"><img src="https://www.linuxtek.ca/wp-content/uploads/2022/10/Screenshot_2022-10-14_16-09-37-1024x395.png" alt="" class="wp-image-694"/></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Investigating further, <a href="https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_CreateContainerService.html">this documentation</a> gave information on how the CreateContainerService API call works, but it didn't point out the specific issue.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The problem ended up being that I was initially trying to create a <strong>Large</strong> capacity container.  Once I switched to testing with a <strong>Medium</strong> size, it worked fine.  I spoke with some contacts via the <a href="https://aws.amazon.com/developer/community/community-builders/">AWS Community Builders Program</a>, and was advised that the error messages around this type of scenario are being improved, and if you hit this issue, to contact Customer Support for assistance, and they should be able to help.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Lightsail Containers are an interesting service, which currently can be leveraged for hosting web applications running inside containers, as well as running other workloads.  There are some limitations, but intial setup can be a lot easier than a full ECS/EKS setup.  </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This article only goes through a basic test.  There are a number of other features in Lightsail Containers which allow communication between containers in a deployment, and horizontal scaling.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Definitely review the documentation and make sure that your use case would be suited to running as a workload on Lightsail.  <a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-frequently-asked-questions-faq">This FAQ</a> may answer some of the more common questions, and this demo video (while a bit older), may be an interesting watch:</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://youtu.be/rsMdqPLmI4U","type":"video","providerNameSlug":"youtube","responsive":true,"align":"center","className":"wp-embed-aspect-16-9 wp-has-aspect-ratio"} -->
<figure class="wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
https://youtu.be/rsMdqPLmI4U
</div></figure>
<!-- /wp:embed -->

<!-- wp:heading -->
<h2>Resources</h2>
<!-- /wp:heading -->

<!-- wp:list -->
<ul><li><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/all">Amazon Lightsail Documentation</a></li><li><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services">Amazon Lightsail Container Service Article</a></li><li><a href="https://aws.amazon.com/blogs/aws/lightsail-containers-an-easy-way-to-run-your-containers-in-the-cloud/">Amazon Lightsail Containers Blog Article</a></li><li><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-changing-container-service-capacity">Amazon Lightsail - Changing Container Service Capacity</a></li><li><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services#container-services-endpoints-domains">Amazon Lightsail - Public Endpoints and Domains</a></li><li><a href="https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-frequently-asked-questions-faq">Amazon Lightsail - Frequently Asked Questions</a></li><li><a href="https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lightsail/index.html">AWS CLI Lightsail Commands</a></li><li><a href="https://hub.docker.com/r/itzg/minecraft-server">itzg/minecraft-server Docker Hub</a></li><li><a href="https://github.com/itzg/docker-minecraft-server/blob/master/README.md">itzg/minecraft-server Github</a></li></ul>
<!-- /wp:list -->