Skip to main content

EC2 Servers

With 10 lines of code to create an EC2 server.

Features

  • Simplifies the creation of EC2 servers on AWS with minimal configuration
  • Uses the high-level Ec2Servers (schema) composite component for easy infrastructure definition
  • Supports customization of instance type (e.g., ARM or AMD architectures)
  • Lets you choose Linux flavor (Amazon Linux 2023 or Ubuntu)
  • Handles networking setup automatically: VPC, subnet, internet gateway, routing
  • Automatically creates a public web traffic security group for your server when a public IP is enabled
  • Automatically manages IAM roles and permissions for your EC2 instances
  • Managing your servers securely with AWS Session Manager without SSH
  • Generates standard Terraform code as an output alongside visual diagrams

Source Code

import { AwsStack } from '@dinghy/tf-aws'
import { Ec2Servers } from '@dinghy/tf-aws/ec2'

export default () => (
<AwsStack>
<Ec2Servers />
</AwsStack>
)

Outputs

Resource types

List of resource types used by this stack, in approximate order of creation:

  1. aws_vpc
  2. aws_default_route_table
  3. aws_internet_gateway
  4. aws_subnet
  5. aws_route
  6. aws_security_group
  7. aws_vpc_security_group_ingress_rule
  8. aws_vpc_security_group_egress_rule
  9. aws_iam_role
  10. aws_iam_role_policy_attachment
  11. aws_iam_instance_profile
  12. data.aws_ami
  13. aws_instance
  14. local_file

Steps to try

Install dinghy-cli

If you haven't already:

curl -fsSL https://get.dinghy.dev/install.sh | sh

Sample Screenshot

Prepare source code

Create my-server.tsx and dinghy.config.yml files with content from above.

curl -fsSL --create-dirs -o ec2-servers/my-server.tsx https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/ec2-servers/my-server.tsx
curl -fsSL --create-dirs -o ec2-servers/dinghy.config.yml https://raw.githubusercontent.com/dinghydev/dinghy/main/sites/www/src/docs/examples/show-cases/ec2-servers/dinghy.config.yml
cd ec2-servers

Preview the actions

Run dinghy tf diff to preview the Terraform actions that will be performed.

info

Make sure your AWS credentials are configured before interacting with AWS services.

dinghy tf diff

Sample Screenshot

Apply the actions

Run dinghy tf deploy to apply the changes and provision your resources.

dinghy tf deploy

Sample Screenshot

Access the server

Once your EC2 server(s) are ready, you can connect to them easily:

dinghy aws connect

Sample Screenshot

Destroy resources

After experimenting, run dinghy tf destroy to remove all resources created in the previous steps.