DEV Community

Kazuo Yagi
Kazuo Yagi

Posted on

Building the development environment on Amazon Linux 2023 with user_data.txt

In my case, requirements for an expected development environment on EC2 are as follows.

Requirements

Mandatory:

  • The following programming language can be available with a specific(latest) version:
    • Ruby
    • Python
    • Node.js
    • Rust
  • Well equipped with build essential and useful tools
    • jq
    • ripgrep(rg)
    • fd(fd-find)
    • fzf

Optional:

  • Could be accessed through EC2 instance connect, the browser-based terminal on AWS Management Console

user_data.txt

https://gist.github.com/kyagi/c28935eeb83b3b03a296a7ed2a179abc#file-user_data-txt

how to run

I use ansible and its collection amazon.aws.ec2_instance collection with my configuration json file with variables to pass over ansible at runtime.

➜ pyenv exec ansible-playbook -i hosts site.yml --extra-vars "@workstation.json"
Enter fullscreen mode Exit fullscreen mode
➜ cat roles/spawn/tasks/main.yml
---
- name: Spawn an ec2 instance
  amazon.aws.ec2_instance:
    name: "{{ instance_name }}"
    key_name: "{{ key_name }}"
    vpc_subnet_id: "{{ vpc_subnet_id }}"
    instance_type: "{{ instance_type }}"
    security_groups: "{{ security_groups }}"
    network:
      assign_public_ip: true
      private_ip_address: "{{ private_ip_address }}"
    image_id: "{{ image_id }}"
    user_data: "{{ lookup('file', 'user_data.txt') }}"
    volumes:
      - device_name: /dev/xvda
        ebs:
          volume_size: 30
          volume_type: gp2
          delete_on_termination: true
    tags:
      Owner: "{{ owner }}"
      Stack: "{{ stack }}"
      Project: "{{ project }}"
      Application: "{{ application }}"
      Ec2InstanceConnectAccess: "{{ ec2_instance_connect_access }}"
Enter fullscreen mode Exit fullscreen mode
➜ cat workstation/workstation.json
{
  "instance_name": "workstation",
  "key_name": "__key-name__",
  "vpc_subnet_id": "__subnet-id__",
  "instance_type": "t4g.small",
  "security_groups": ["__sg-id1__", "__sg-id2__"],
  "private_ip_address": "10.0.0.10",
  "image_id": "resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64",
  "owner": "kyagi",
  "stack": "deveplopment",
  "project": "workstation",
  "application": "hodgepodge of development tools",
  "ec2_instance_connect_access": "true"
}
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️