Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

AWS PowerShell Automation Scripts

This directory contains PowerShell scripts that automate AWS operations using the AWS.Tools PowerShell modules. All scripts are designed to be standalone, modular, and follow consistent patterns for parameter validation and error handling.

Prerequisites

  • PowerShell 5.1+: Windows PowerShell or PowerShell Core
  • AWS.Tools Modules: Automatically installed by scripts when needed
  • AWS Credentials: Configured via AWS credentials file or environment variables

Authentication

Scripts authenticate using AWS PowerShell credential management:

# Set default AWS credentials
Set-AWSCredential -AccessKey "your-access-key" -SecretKey "your-secret-key"

# Or use profiles
Set-AWSCredential -ProfileName "default"

# Or use IAM roles (when running on EC2)

Directory Structure

Folder Description Service Focus
appstream/ AppStream 2.0 management Virtual application streaming
ec2/ EC2 instance management Virtual machines, security groups
nice-dcv/ NICE DCV integration Remote desktop sessions
rds/ RDS database management Database instances and operations
workspaces/ Amazon WorkSpaces Virtual desktop management

Common Usage Patterns

Module Installation

Scripts automatically install required AWS.Tools modules:

function Test-AWSModule {
    param($ModuleName)

    if (-not (Get-Module -Name $ModuleName -ListAvailable)) {
        Write-Host "Installing $ModuleName..." -ForegroundColor Yellow
        Install-Module -Name $ModuleName -Force -AllowClobber -Scope CurrentUser
    }
    Import-Module $ModuleName -Force
}

Parameter Validation

All scripts use comprehensive validation:

[ValidateSet("us-east-1", "us-west-2", "eu-west-1")]
[string]$Region

[ValidatePattern('^i-[0-9a-f]{8,17}$')]
[string]$InstanceId

[ValidateRange(1, 100)]
[int]$InstanceCount

Error Handling

Scripts implement robust error handling:

$ErrorActionPreference = 'Stop'
try {
    # AWS PowerShell operations
    $result = Get-EC2Instance -InstanceId $InstanceId -Region $Region
}
catch {
    Write-Error "Operation failed: $($_.Exception.Message)"
    exit 1
}

Quick Start Examples

Create EC2 Instance

.\ec2\aws-ps-create-ec2-instance.ps1 `
  -InstanceName "MyServer" `
  -InstanceType "t3.micro" `
  -Region "us-east-1" `
  -KeyPairName "my-keypair"

Manage AppStream

.\appstream\appstream-quickstart.ps1 `
  -FleetName "MyFleet" `
  -StackName "MyStack" `
  -Region "us-east-1" `
  -InstanceType "stream.standard.medium"

WorkSpaces Management

.\workspaces\aws-ps-create-workspace.ps1 `
  -DirectoryId "d-12345678" `
  -Username "testuser" `
  -BundleId "wsb-12345678" `
  -Region "us-east-1"

Security Considerations

  1. Credential Management: Use AWS credential profiles instead of hardcoded keys
  2. Resource Tagging: All resources are tagged for management and billing
  3. Input Validation: All parameters are validated before API calls
  4. Least Privilege: Scripts assume minimal required permissions

Best Practices

  1. Module Management: Scripts handle AWS.Tools module installation automatically
  2. Region Specification: Always specify AWS regions explicitly
  3. Error Recovery: Include comprehensive error handling and cleanup
  4. Resource Cleanup: Provide cleanup scripts for test resources
  5. Documentation: Each script includes detailed help and examples

Troubleshooting

Common Issues

  1. Module Not Found

    Module 'AWS.Tools.EC2' not found
    
    • Solution: Scripts auto-install modules or run Install-Module AWS.Tools.EC2
  2. Credentials Not Set

    No credentials specified or found
    
    • Solution: Configure AWS credentials using Set-AWSCredential
  3. Region Not Specified

    No default region specified
    
    • Solution: Specify -Region parameter or set Set-DefaultAWSRegion
  4. Permission Denied

    User is not authorized to perform this operation
    
    • Solution: Verify IAM permissions for the AWS service

Script Features

Common Parameters

Most scripts support these standard parameters:

  • Region: AWS region for operations
  • ProfileName: AWS credential profile to use
  • Force: Skip confirmation prompts
  • WhatIf: Show what would be done without executing
  • Verbose: Detailed operation logging

Error Handling

  • Automatic retry logic for transient failures
  • Comprehensive error messages with suggested solutions
  • Cleanup of partially created resources on failure

Logging

  • Detailed progress reporting
  • Success/failure status for each operation
  • Performance metrics for operations

Contributing

When adding new scripts:

  1. Follow the established parameter validation patterns
  2. Include automatic module installation
  3. Add comprehensive error handling with cleanup
  4. Include detailed help documentation with examples
  5. Test with multiple AWS regions and scenarios
  6. Update this README with new script descriptions

Module Dependencies

Common AWS.Tools modules used:

  • AWS.Tools.Common: Core AWS functionality
  • AWS.Tools.EC2: EC2 operations
  • AWS.Tools.AppStream: AppStream 2.0 operations
  • AWS.Tools.WorkSpaces: WorkSpaces operations
  • AWS.Tools.RDS: RDS database operations

Support

For issues or questions:

  1. Check the individual script help documentation
  2. Review AWS PowerShell documentation
  3. Consult AWS service-specific PowerShell cmdlet reference
  4. Verify AWS credentials and permissions