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"
➜ 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 }}"
➜ 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"
}
Top comments (0)