Skip to content

AWS Integration Guide for Nstance

This document provides a comprehensive overview of how Nstance integrates with AWS services, including the specific APIs used, IAM permissions required, and operational considerations.

Overview

Nstance Server leverages multiple AWS services for infrastructure management, configuration storage, secrets management, and load balancing. The server uses AWS SDK v2 and requires specific IAM permissions to operate.

AWS Services Used

1. Amazon EC2 (Elastic Compute Cloud)

Nstance uses EC2 for virtual machine lifecycle management across multiple operations:

  • Instance Provisioning: Creating new EC2 instances with custom configurations
  • Instance Termination: Gracefully shutting down unhealthy or expired instances
  • Health Monitoring: Querying instance status for reconciliation decisions
  • Leader Network Management: Attaching/detaching ENIs for shard leadership
  • Capacity Planning: Checking subnet IP address availability
  • AMI Resolution: Looking up latest AMIs for instance templates

Key Features:

  • Support for all EC2 instance types (including ARM64)
  • Custom IAM instance profiles and security groups
  • Userdata injection for agent initialization
  • Tag-based instance identification and management

2. Amazon S3 (Object Storage)

S3 serves as the object storage backend for all persistent state:

  • Configuration Storage: Static and dynamic group configurations
  • Instance Metadata: Registration records and certificates
  • Leader Election: Distributed coordination using S3 lockfiles
  • Certificate Logs: Audit trail of certificate issuances
  • (Optionally) Secrets Storage: Encrypted CA keys and custom secrets

See Data Storage for the full bucket layout.

3. AWS Secrets Manager

Used for secure storage of sensitive cryptographic material:

  • Encryption Key: For encrypting data stored in object storage
  • Certificate Authority Keys: Private keys for CA operations
  • Service Account Keys: Kubernetes service account signing keys
  • Custom Secrets: Distributed to instances via agent

Security Model:

  • Encryption Key reduces required permissions (read-only access to Secrets Manager)
  • Secrets are encrypted at rest and in transit
  • Supports key rotation workflows

4. Elastic Load Balancing v2 (ELBv2)

Manages Network Load Balancer target groups for service exposure:

  • Target Registration: Adding healthy instances to NLB target groups
  • Target Deregistration: Removing instances during termination/drain
  • Health Monitoring: Querying target health status

Supported Load Balancers:

  • Network Load Balancers (NLB) for high-performance TCP/UDP load balancing
  • Automatic registration/deregistration based on instance lifecycle

AWS SDK API Usage

EC2 APIs

SDK MethodIAM ActionPurpose
RunInstancesec2:RunInstancesCreate new EC2 instances
TerminateInstancesec2:TerminateInstancesTerminate instances
DescribeInstancesec2:DescribeInstancesQuery instance status/metadata
DescribeNetworkInterfacesec2:DescribeNetworkInterfacesENI status for leader network operations
AttachNetworkInterfaceec2:AttachNetworkInterfaceAssign leader network (attach ENI to new leader)
DetachNetworkInterfaceec2:DetachNetworkInterfaceRelease leader network (detach ENI from old leader)
DescribeSubnetsec2:DescribeSubnetsCheck subnet IP availability
DescribeImagesec2:DescribeImagesResolve AMI IDs from filters

S3 APIs

SDK MethodIAM ActionPurpose
GetObjects3:GetObjectRetrieve stored data
PutObjects3:PutObjectStore/update data
DeleteObjects3:DeleteObjectRemove data
HeadObjects3:GetObjectCheck object existence/metadata
ListObjectsV2s3:ListBucketEnumerate stored objects

Secrets Manager APIs

SDK MethodIAM ActionPurpose
GetSecretValuesecretsmanager:GetSecretValueRetrieve secret values
UpdateSecretsecretsmanager:UpdateSecretUpdate existing secrets
CreateSecretsecretsmanager:CreateSecretCreate new secrets
DeleteSecretsecretsmanager:DeleteSecretRemove secrets

ELBv2 APIs

SDK MethodIAM ActionPurpose
RegisterTargetselasticloadbalancing:RegisterTargetsAdd instances to target groups
DeregisterTargetselasticloadbalancing:DeregisterTargetsRemove instances from target groups
DescribeTargetHealthelasticloadbalancing:DescribeTargetHealthQuery target health status

IAM Permissions

Nstance Server requires a dedicated IAM role with specific permissions. The complete policy is available in server-aws-iam.json.

Key Considerations

  • Resource Scoping: S3 permissions are scoped to specific buckets
  • Secret Prefixing: Secrets Manager access limited to nstance/* prefix
  • Regional Scope: All permissions should be scoped to the deployment region
  • Tag-Based Access: Consider adding tag-based conditions for EC2 resources

Troubleshooting

Common Issues

  1. IAM Permission Errors: Verify the IAM policy matches examples/server-aws-iam.json
  2. S3 Access Denied: Check bucket permissions and KMS encryption settings
  3. EC2 Launch Failures: Verify subnet capacity and security group rules
  4. Leader Network Issues: Ensure ENI exists and is in correct VPC/subnet

Debugging Commands

# Check EC2 instance status
aws ec2 describe-instances --instance-ids i-1234567890abcdef0

# List S3 objects
aws s3 ls s3://your-bucket/ --recursive

# Check secrets access
aws secretsmanager list-secrets --include-planned-deletion

# Verify target group health
aws elbv2 describe-target-health --target-group-arn arn:aws:elasticloadbalancing:...

Further Reading