Connect your tools
Point SDKs, the cloud CLIs, Terraform and the CDK at pogi.
Before you start: pogi is running (pogi start). The commands below find it at http://localhost:7644. If it runs on another port, pass --endpoint to client commands, or set POGI_ENDPOINT.
SDKs and CLIs
pogi env prints the settings that point every cloud tool at pogi.
- Load them into your shell. Pick the tab for your shell:
eval "$(pogi env)"| Shell | Output |
|---|---|
sh | export NAME="value" lines. |
fish | set -gx NAME "value"; lines. |
pwsh | $env:NAME="value" lines. Run them in your session. |
dotenv | NAME=value lines, for tools that read a .env file. |
- Use your tools as usual. The sections below say what
pogi envsets for each cloud.
AWS
pogi env sets AWS_ENDPOINT_URL, AWS_ and AWS_ (both test), AWS_ and AWS_REGION. Every current AWS SDK and the AWS CLI read AWS_ENDPOINT_URL, so your code does not change. This Go program lists buckets with no pogi-specific code:
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func main() {
ctx := context.Background()
cfg, err := config.LoadDefaultConfig(ctx) // reads AWS_ENDPOINT_URL and the test credentials
if err != nil {
panic(err)
}
out, err := s3.NewFromConfig(cfg).ListBuckets(ctx, &s3.ListBucketsInput{})
if err != nil {
panic(err)
}
for _, b := range out.Buckets {
fmt.Println(*b.Name)
}
}With a bucket called demo, it prints:
demoTo run the AWS CLI without loading the variables, use pogi aws. It needs the AWS CLI installed.
pogi aws s3 lsGoogle Cloud
pogi env sets STORAGE_, PUBSUB_, FIRESTORE_, DATASTORE_ and, for the Firebase Admin SDK, FIREBASE_. The client libraries read them. It also sets the gcloud settings (CLOUDSDK_, project pogi), so gcloud talks to pogi.
Azure
pogi env sets AZURE_ (Azurite ports 10000 to 10002), and COSMOS_ENDPOINT, COSMOS_KEY and AZURE_ on the HTTPS port. HTTPS services use pogi's own certificate authority (CA). Run pogi cert to see where it is and how to trust it.
S3 with bucket names in the host
Some code needs the bucket in the host name (<bucket>.s3.aws.localhost).
-
Start pogi with a host name:
pogi start --hostname aws.localhost -
Print matching settings:
pogi env --hostname aws.localhostOutput export AWS_ENDPOINT_URL="http://aws.localhost:7644" export AWS_ENDPOINT_URL_S3="http://s3.aws.localhost:7644" …To load them, run
eval "$(pogi env --hostname aws.localhost)".
pogi doctor tells you whether *.localhost names resolve on your machine.
Terraform
pogi tf prints a provider block with every endpoint pointed at pogi.
-
Write it next to your own files. Terraform loads
*_override.tffiles over your own settings, so your configuration stays as it is:pogi tf > pogi_override.tfThe file starts like this:
pogi_override.tf # Generated by "pogi tf": point the AWS provider at pogi. provider "aws" { region = "us-east-1" access_key = "test" secret_key = "test" skip_credentials_validation = true skip_metadata_api_check = true skip_requesting_account_id = false s3_use_path_style = true -
Run Terraform:
terraform init terraform apply
For the other clouds:
pogi tf --cloud gcp > pogi_override.tf
pogi tf --cloud azure > pogi_override.tf| Flag | Meaning |
|---|---|
--cloud | aws (default), gcp or azure. |
--region | Region. Default us-east-1 for AWS, us-central1 for Google Cloud. |
--project | Google Cloud project. Default pogi. |
--endpoint | pogi's address. |
--metadata-host | host:port for the azurerm provider. |
The azurerm provider needs HTTPS. The Azure output starts with comments that show how to run Terraform in a container that trusts pogi's CA.
CDK
No wrapper is needed, and custom resources work, including the CDK provider framework.
-
Set
AWS_ENDPOINT_URLand the test credentials in your shell:eval "$(pogi env)" -
Run
pogi lambda-sdksonce. It gives native Lambda functions the AWS SDKs that real Lambda runtimes include: the JavaScript v3 SDK fromnpmandboto3frompip, in pogi's data folder. You need Node.js and Python on your machine.pogi lambda-sdks -
Bootstrap and deploy:
cdk bootstrap cdk deploy
Go tests
-
Start pogi inside the test, and set the environment for the code under test:
srv := pogi.Start(t) // in-process on a random port, cleaned up with the test srv.Setenv(t) // AWS_ENDPOINT_URL, *_EMULATOR_HOST, Azure settings for code under test -
Build your client as usual. It now points at pogi:
cfg, _ := config.LoadDefaultConfig(ctx)
pogi.Start(t) runs everything inside the test process, with no container. With pogi.Start(t, cfg) and cfg, _ := pogi.LoadConfig("testdata/pogi.yaml"), it also creates what the pogi.yaml file lists.
With Testcontainers, run the ghcr.io/ image, expose port 7644, and wait for the log line Ready. or for /_localstack/.
Check that it works
-
Check that pogi is up:
pogi status -
Follow every call your tools make:
pogi logs -f
If a call does not show up, your tool is not using the endpoint from pogi env. See Troubleshoot.