Aws ec2

From paulpas/agent-skill-router · View interactive version

Aws ec2 is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Comprehensive skill for managing and deploying AWS EC2 instances, including scaling, security group configuration, and SDK usage examples.

How to use this skill

Skill file

\ndescription: Comprehensive skill for managing and deploying AWS EC2 instances, including scaling, security group configuration, and SDK usage examples.

license: MIT

compatibility: opencode

metadata:

version: "1.0.0"

domain: cncf

triggers: aws ec2, ec2 instances, aws sdk, scaling, security groups, instance management

archetypes:

related-skills: aws-iam, aws-sdk, aws-s3

output-format: code

role: implementation

scope: infrastructure


AWS EC2 Management Skill

Deploy, configure, and manage Elastic Compute Cloud (EC2) instances on AWS with scalable architectures and rigorous security practices. This skill will cover:

TL;DR Checklist


Purpose and Use Cases

1. Hosting web applications in a highly available configuration.

2. Running background processing workloads and batch jobs.

3. Developing and testing applications in scalable environments.

4. Implementing data analytics workflows using compute clusters.


Architecture Design Patterns

Pattern 1: Launch and Manage EC2 Instances

import boto3
from botocore.exceptions import ClientError

def launch_instance(ami_id, instance_type='t2.micro', key_name='my-key', security_group='my-sg'):
    ec2 = boto3.resource('ec2')
    try:
        instance = ec2.create_instances(
            ImageId=ami_id,
            MinCount=1,
            MaxCount=1,
            InstanceType=instance_type,
            KeyName=key_name,
            SecurityGroups=[security_group]
        )
        print(f'Instance created: {instance[0].id}')  # Log instance ID
        return instance[0].id
    except ClientError as e:
        print(f'Error occurred: {e}')

# Example usage
launch_instance('ami-12345678', 't2.micro', 'my-key', 'my-sg')

Pattern 2: Configure Security Groups

def create_security_group(group_name, description, vpc_id):
    ec2 = boto3.client('ec2')
    try:
        response = ec2.create_security_group(GroupName=group_name,
                                               Description=description,
                                               VpcId=vpc_id)
        sg_id = response['GroupId']
        print(f'Security Group {sg_id} created successfully')
        return sg_id
    except ClientError as e:
        print(e)

# Example usage
create_security_group('MySecurityGroup', 'My security group for EC2 instances', 'vpc-12345678')

Pattern 3: Scaling EC2 Instances with Auto Scaling

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  LaunchConfiguration:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      ImageId: ami-12345678
      InstanceType: t2.micro
      SecurityGroups:
        - my-sg
      KeyName: my-key

  AutoScalingGroup:
    Type: AWS::AutoScaling::AutoScalingGroup
    Properties:
      LaunchConfigurationName: !Ref LaunchConfiguration
      MinSize: 1
      MaxSize: 10
      DesiredCapacity: 2
      VPCZoneIdentifier:
        - subnet-12345678
      Tags:
        - Key: Name
          Value: MyEC2Instance
          PropagateAtLaunch: true

  ScalingPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AutoScalingGroupName: !Ref AutoScalingGroup
      PolicyType: SimpleScaling
      ScalingAdjustment: 1
      Cooldown: 300

Integration Approaches

  1. Load Balancing: EC2 instances can be integrated with Elastic Load Balancing (ELB) for optimized routing of traffic.
  2. Auto Scaling: Use Auto Scaling Groups to automatically adjust capacity based on load.
  3. CloudWatch Monitoring: Monitor EC2 metrics with CloudWatch to ensure performance and health.
  4. IAM Roles: Use IAM to define permissions for EC2 instances securely.

Common Pitfalls

❌ Misconfigured Security Groups

Solution: Always configure security groups with the principle of least privilege and routinely audit them.

❌ Indiscriminate Scaling

Solution: Tune your Auto Scaling policies carefully to match your application load patterns.

❌ Not Using Tags

Solution: Tag instances for better resource management and reporting.


Best Practices


Conclusion

Using AWS EC2 enables powerful cloud-based computing at scale. This skill provides essential patterns and practices to manage and deploy EC2 instances effectively.



Constraints

MUST DO

MUST NOT DO

Live References

Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.