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.
- 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
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)| 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 |
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
}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]$InstanceCountScripts 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
}.\ec2\aws-ps-create-ec2-instance.ps1 `
-InstanceName "MyServer" `
-InstanceType "t3.micro" `
-Region "us-east-1" `
-KeyPairName "my-keypair".\appstream\appstream-quickstart.ps1 `
-FleetName "MyFleet" `
-StackName "MyStack" `
-Region "us-east-1" `
-InstanceType "stream.standard.medium".\workspaces\aws-ps-create-workspace.ps1 `
-DirectoryId "d-12345678" `
-Username "testuser" `
-BundleId "wsb-12345678" `
-Region "us-east-1"- Credential Management: Use AWS credential profiles instead of hardcoded keys
- Resource Tagging: All resources are tagged for management and billing
- Input Validation: All parameters are validated before API calls
- Least Privilege: Scripts assume minimal required permissions
- Module Management: Scripts handle AWS.Tools module installation automatically
- Region Specification: Always specify AWS regions explicitly
- Error Recovery: Include comprehensive error handling and cleanup
- Resource Cleanup: Provide cleanup scripts for test resources
- Documentation: Each script includes detailed help and examples
-
Module Not Found
Module 'AWS.Tools.EC2' not found- Solution: Scripts auto-install modules or run
Install-Module AWS.Tools.EC2
- Solution: Scripts auto-install modules or run
-
Credentials Not Set
No credentials specified or found- Solution: Configure AWS credentials using
Set-AWSCredential
- Solution: Configure AWS credentials using
-
Region Not Specified
No default region specified- Solution: Specify
-Regionparameter or setSet-DefaultAWSRegion
- Solution: Specify
-
Permission Denied
User is not authorized to perform this operation- Solution: Verify IAM permissions for the AWS service
Most scripts support these standard parameters:
Region: AWS region for operationsProfileName: AWS credential profile to useForce: Skip confirmation promptsWhatIf: Show what would be done without executingVerbose: Detailed operation logging
- Automatic retry logic for transient failures
- Comprehensive error messages with suggested solutions
- Cleanup of partially created resources on failure
- Detailed progress reporting
- Success/failure status for each operation
- Performance metrics for operations
When adding new scripts:
- Follow the established parameter validation patterns
- Include automatic module installation
- Add comprehensive error handling with cleanup
- Include detailed help documentation with examples
- Test with multiple AWS regions and scenarios
- Update this README with new script descriptions
Common AWS.Tools modules used:
AWS.Tools.Common: Core AWS functionalityAWS.Tools.EC2: EC2 operationsAWS.Tools.AppStream: AppStream 2.0 operationsAWS.Tools.WorkSpaces: WorkSpaces operationsAWS.Tools.RDS: RDS database operations
For issues or questions:
- Check the individual script help documentation
- Review AWS PowerShell documentation
- Consult AWS service-specific PowerShell cmdlet reference
- Verify AWS credentials and permissions