Documentation
¶
Overview ¶
Package awsmock provides an in-memory mock of AWS services for testing.
awsmock starts a local HTTP server that emulates AWS service APIs, allowing you to test code that uses the AWS SDK for Go v2 without making real API calls.
Quick Start ¶
func TestMyFunction(t *testing.T) {
mock := awsmock.Start(t)
cfg := mock.AWSConfig(context.Background())
client := s3.NewFromConfig(cfg)
_, err := client.CreateBucket(ctx, &s3.CreateBucketInput{
Bucket: aws.String("my-bucket"),
})
if err != nil {
t.Fatal(err)
}
}
Supported Services ¶
awsmock currently supports the following AWS services:
- S3 (Simple Storage Service)
- SQS (Simple Queue Service)
- STS (Security Token Service)
- DynamoDB
- SNS (Simple Notification Service)
- Secrets Manager
- Lambda
- CloudWatch Logs
- IAM (Identity and Access Management)
- EC2 (Elastic Compute Cloud)
- Kinesis Data Streams
- EventBridge
- SSM Parameter Store
- KMS (Key Management Service)
- CloudFormation
- ECR (Elastic Container Registry)
- Route 53 (DNS)
- ECS (Elastic Container Service)
- ELBv2 (Elastic Load Balancing v2)
- RDS (Relational Database Service)
- CloudWatch (Metrics and Alarms)
- Step Functions
- ACM (Certificate Manager)
- SES v2 (Simple Email Service)
- Cognito Identity Provider
- API Gateway V2 (HTTP/WebSocket APIs)
- CloudFront (CDN)
- EKS (Elastic Kubernetes Service)
- ElastiCache (Redis/Memcached)
- Firehose (Kinesis Data Firehose)
- Athena (SQL Query Service)
- Glue (ETL/Data Catalog)
- Auto Scaling
- API Gateway (REST APIs)
- Cognito Identity (Federated Identities)
- Organizations
- DynamoDB Streams
- EFS (Elastic File System)
- Batch
- CodeBuild
- CodePipeline
- CloudTrail
- Config
- WAF v2 (Web Application Firewall)
- Redshift
- EMR (Elastic MapReduce)
- Backup
- EventBridge Scheduler
- X-Ray
- OpenSearch
- Service Discovery (Cloud Map)
- Transfer Family (SFTP/FTPS/FTP)
- Application Auto Scaling
- Resource Groups Tagging API
- SSO Admin (IAM Identity Center)
- AppSync (GraphQL)
- MSK (Managed Streaming for Kafka)
- Neptune (Graph Database)
- GuardDuty (Threat Detection)
- Amazon MQ (Message Broker)
- DAX (DynamoDB Accelerator)
- FSx (Managed File Systems)
Additional services can be added by implementing the Service interface.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockServer ¶
type MockServer struct {
// contains filtered or unexported fields
}
MockServer is a mock AWS server that routes requests to service handlers.
func Start ¶
func Start(t testing.TB, opts ...Option) *MockServer
Start creates and starts a new mock AWS server with all built-in services. The server is automatically stopped when the test completes.
func (*MockServer) AWSConfig ¶
AWSConfig returns an aws.Config pre-configured to route all requests to the mock server with static test credentials.
func (*MockServer) Register ¶
func (m *MockServer) Register(svc Service)
Register adds a service to the mock server. If a service with the same name already exists, it is replaced.
func (*MockServer) Reset ¶
func (m *MockServer) Reset()
Reset clears all in-memory state across all registered services.
func (*MockServer) ServeHTTP ¶
func (m *MockServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP routes incoming requests to the appropriate service handler. It determines the target service by inspecting the Authorization header's credential scope (e.g., ".../s3/aws4_request").
func (*MockServer) Stop ¶
func (m *MockServer) Stop()
Stop shuts down the mock server and resets all services.
func (*MockServer) URL ¶
func (m *MockServer) URL() string
URL returns the base URL of the mock server.
type Option ¶
type Option func(*serverConfig)
Option configures a MockServer.
func WithService ¶
WithService registers an additional Service with the mock server. Use this to add custom service implementations or override built-in ones.
type Service ¶
type Service interface {
// Name returns the AWS service identifier (e.g., "s3", "sqs", "sts").
Name() string
// Handler returns the HTTP handler for this service.
Handler() http.Handler
// Reset clears all in-memory state for the service.
Reset()
}
Service represents an AWS service mock that can handle HTTP requests.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
mockhelpers
Package mockhelpers provides shared helper functions for mock AWS services.
|
Package mockhelpers provides shared helper functions for mock AWS services. |
|
services
|
|
|
acm
Package acm provides a mock implementation of AWS Certificate Manager.
|
Package acm provides a mock implementation of AWS Certificate Manager. |
|
apigateway
Package apigateway provides a mock implementation of AWS API Gateway v1 (REST APIs).
|
Package apigateway provides a mock implementation of AWS API Gateway v1 (REST APIs). |
|
apigatewayv2
Package apigatewayv2 provides a mock implementation of AWS API Gateway V2 (HTTP/WebSocket APIs).
|
Package apigatewayv2 provides a mock implementation of AWS API Gateway V2 (HTTP/WebSocket APIs). |
|
applicationautoscaling
Package applicationautoscaling provides a mock implementation of AWS Application Auto Scaling.
|
Package applicationautoscaling provides a mock implementation of AWS Application Auto Scaling. |
|
appsync
Package appsync provides a mock implementation of AWS AppSync.
|
Package appsync provides a mock implementation of AWS AppSync. |
|
athena
Package athena provides a mock implementation of AWS Athena.
|
Package athena provides a mock implementation of AWS Athena. |
|
autoscaling
Package autoscaling provides a mock implementation of AWS Auto Scaling.
|
Package autoscaling provides a mock implementation of AWS Auto Scaling. |
|
backup
Package backup provides a mock implementation of AWS Backup.
|
Package backup provides a mock implementation of AWS Backup. |
|
batch
Package batch provides a mock implementation of AWS Batch.
|
Package batch provides a mock implementation of AWS Batch. |
|
cloudformation
Package cloudformation provides a mock implementation of AWS CloudFormation.
|
Package cloudformation provides a mock implementation of AWS CloudFormation. |
|
cloudfront
Package cloudfront provides a mock implementation of AWS CloudFront.
|
Package cloudfront provides a mock implementation of AWS CloudFront. |
|
cloudtrail
Package cloudtrail provides a mock implementation of AWS CloudTrail.
|
Package cloudtrail provides a mock implementation of AWS CloudTrail. |
|
cloudwatch
Package cloudwatch provides a mock implementation of AWS CloudWatch (metrics).
|
Package cloudwatch provides a mock implementation of AWS CloudWatch (metrics). |
|
cloudwatchlogs
Package cloudwatchlogs provides a mock implementation of AWS CloudWatch Logs.
|
Package cloudwatchlogs provides a mock implementation of AWS CloudWatch Logs. |
|
codebuild
Package codebuild provides a mock implementation of AWS CodeBuild.
|
Package codebuild provides a mock implementation of AWS CodeBuild. |
|
codepipeline
Package codepipeline provides a mock implementation of AWS CodePipeline.
|
Package codepipeline provides a mock implementation of AWS CodePipeline. |
|
cognitoidentity
Package cognitoidentity provides a mock implementation of AWS Cognito Identity.
|
Package cognitoidentity provides a mock implementation of AWS Cognito Identity. |
|
cognitoidp
Package cognitoidp provides a mock implementation of AWS Cognito Identity Provider.
|
Package cognitoidp provides a mock implementation of AWS Cognito Identity Provider. |
|
configservice
Package configservice provides a mock implementation of AWS Config.
|
Package configservice provides a mock implementation of AWS Config. |
|
dax
Package dax provides a mock implementation of Amazon DAX.
|
Package dax provides a mock implementation of Amazon DAX. |
|
dynamodb
Package dynamodb provides a mock implementation of AWS DynamoDB.
|
Package dynamodb provides a mock implementation of AWS DynamoDB. |
|
dynamodbstreams
Package dynamodbstreams provides a mock implementation of AWS DynamoDB Streams.
|
Package dynamodbstreams provides a mock implementation of AWS DynamoDB Streams. |
|
ec2
Package ec2 provides a mock implementation of AWS Elastic Compute Cloud.
|
Package ec2 provides a mock implementation of AWS Elastic Compute Cloud. |
|
ecr
Package ecr provides a mock implementation of AWS Elastic Container Registry.
|
Package ecr provides a mock implementation of AWS Elastic Container Registry. |
|
ecs
Package ecs provides a mock implementation of AWS Elastic Container Service.
|
Package ecs provides a mock implementation of AWS Elastic Container Service. |
|
efs
Package efs provides a mock implementation of AWS Elastic File System.
|
Package efs provides a mock implementation of AWS Elastic File System. |
|
eks
Package eks provides a mock implementation of AWS Elastic Kubernetes Service.
|
Package eks provides a mock implementation of AWS Elastic Kubernetes Service. |
|
elasticache
Package elasticache provides a mock implementation of AWS ElastiCache.
|
Package elasticache provides a mock implementation of AWS ElastiCache. |
|
elbv2
Package elbv2 provides a mock implementation of AWS Elastic Load Balancing v2.
|
Package elbv2 provides a mock implementation of AWS Elastic Load Balancing v2. |
|
emr
Package emr provides a mock implementation of AWS EMR (Elastic MapReduce).
|
Package emr provides a mock implementation of AWS EMR (Elastic MapReduce). |
|
eventbridge
Package eventbridge provides a mock implementation of AWS EventBridge.
|
Package eventbridge provides a mock implementation of AWS EventBridge. |
|
firehose
Package firehose provides a mock implementation of AWS Kinesis Data Firehose.
|
Package firehose provides a mock implementation of AWS Kinesis Data Firehose. |
|
fsx
Package fsx provides a mock implementation of AWS FSx.
|
Package fsx provides a mock implementation of AWS FSx. |
|
glue
Package glue provides a mock implementation of AWS Glue.
|
Package glue provides a mock implementation of AWS Glue. |
|
guardduty
Package guardduty provides a mock implementation of AWS GuardDuty.
|
Package guardduty provides a mock implementation of AWS GuardDuty. |
|
iam
Package iam provides a mock implementation of AWS Identity and Access Management.
|
Package iam provides a mock implementation of AWS Identity and Access Management. |
|
kafka
Package kafka provides a mock implementation of Amazon Managed Streaming for Apache Kafka (MSK).
|
Package kafka provides a mock implementation of Amazon Managed Streaming for Apache Kafka (MSK). |
|
kinesis
Package kinesis provides a mock implementation of AWS Kinesis Data Streams.
|
Package kinesis provides a mock implementation of AWS Kinesis Data Streams. |
|
kms
Package kms provides a mock implementation of AWS Key Management Service.
|
Package kms provides a mock implementation of AWS Key Management Service. |
|
lambda
Package lambda provides a mock implementation of AWS Lambda.
|
Package lambda provides a mock implementation of AWS Lambda. |
|
mq
Package mq provides a mock implementation of Amazon MQ.
|
Package mq provides a mock implementation of Amazon MQ. |
|
neptune
Package neptune provides a mock implementation of AWS Neptune.
|
Package neptune provides a mock implementation of AWS Neptune. |
|
opensearch
Package opensearch provides a mock implementation of Amazon OpenSearch Service.
|
Package opensearch provides a mock implementation of Amazon OpenSearch Service. |
|
organizations
Package organizations provides a mock implementation of AWS Organizations.
|
Package organizations provides a mock implementation of AWS Organizations. |
|
rds
Package rds provides a mock implementation of AWS Relational Database Service.
|
Package rds provides a mock implementation of AWS Relational Database Service. |
|
redshift
Package redshift provides a mock implementation of AWS Redshift.
|
Package redshift provides a mock implementation of AWS Redshift. |
|
resourcegroupstaggingapi
Package resourcegroupstaggingapi provides a mock implementation of AWS Resource Groups Tagging API.
|
Package resourcegroupstaggingapi provides a mock implementation of AWS Resource Groups Tagging API. |
|
route53
Package route53 provides a mock implementation of AWS Route 53.
|
Package route53 provides a mock implementation of AWS Route 53. |
|
s3
Package s3 provides a mock implementation of AWS Simple Storage Service.
|
Package s3 provides a mock implementation of AWS Simple Storage Service. |
|
scheduler
Package scheduler provides a mock implementation of Amazon EventBridge Scheduler.
|
Package scheduler provides a mock implementation of Amazon EventBridge Scheduler. |
|
secretsmanager
Package secretsmanager provides a mock implementation of AWS Secrets Manager.
|
Package secretsmanager provides a mock implementation of AWS Secrets Manager. |
|
servicediscovery
Package servicediscovery provides a mock implementation of AWS Cloud Map (Service Discovery).
|
Package servicediscovery provides a mock implementation of AWS Cloud Map (Service Discovery). |
|
ses
Package ses provides a mock implementation of AWS Simple Email Service (SES v2).
|
Package ses provides a mock implementation of AWS Simple Email Service (SES v2). |
|
sns
Package sns provides a mock implementation of AWS Simple Notification Service.
|
Package sns provides a mock implementation of AWS Simple Notification Service. |
|
sqs
Package sqs provides a mock implementation of AWS Simple Queue Service.
|
Package sqs provides a mock implementation of AWS Simple Queue Service. |
|
ssm
Package ssm provides a mock implementation of AWS Systems Manager Parameter Store.
|
Package ssm provides a mock implementation of AWS Systems Manager Parameter Store. |
|
ssoadmin
Package ssoadmin provides a mock implementation of AWS SSO Admin.
|
Package ssoadmin provides a mock implementation of AWS SSO Admin. |
|
stepfunctions
Package stepfunctions provides a mock implementation of AWS Step Functions.
|
Package stepfunctions provides a mock implementation of AWS Step Functions. |
|
sts
Package sts provides a mock implementation of AWS Security Token Service.
|
Package sts provides a mock implementation of AWS Security Token Service. |
|
transfer
Package transfer provides a mock implementation of AWS Transfer Family.
|
Package transfer provides a mock implementation of AWS Transfer Family. |
|
wafv2
Package wafv2 provides a mock implementation of AWS WAF v2.
|
Package wafv2 provides a mock implementation of AWS WAF v2. |
|
xray
Package xray provides a mock implementation of AWS X-Ray.
|
Package xray provides a mock implementation of AWS X-Ray. |