community/mock-preset-aws

A service preset for aux4/mock that stands up AWS STS GetCallerIdentity on a running mock server with a single command. Install it and aux4 mock preset aws becomes available — the mock core stays preset-agnostic and knows nothing about AWS.

Unlike the OAuth-based presets, AWS does not use bearer auth — it signs requests with SigV4. So this preset is deliberately minimal: a single POST / stub matched on the request body containing GetCallerIdentity (rather than a bearer header). Everything else your test needs should be stubbed explicitly with aux4 mock stub.

This is a pure .aux4 package (no binary, no bundle). It works entirely by contributing an aws command into aux4/mock's mock:preset profile via aux4's global.aux4 profile merge.

Installation

aux4 aux4 pkger install community/mock-preset-aws

Installing this package pulls in aux4/mock as a dependency.

Usage

aux4 mock start --port 8080
aux4 mock preset aws --port 8080
stub POST / -> 200

Confirm it is installed and visible to the mock:

aux4 mock presets
Installed presets (apply with: aux4 mock preset <service> --port <port>):
  aws

What it stubs

| Method + Path | Match | Status | Behavior | |---------------|-------|--------|----------| | POST / | request body contains GetCallerIdentity | 200 | STS GetCallerIdentityResponse (Account, Arn, UserId) |

The stub is gated on the request body substring GetCallerIdentity — not a header — because AWS clients sign with SigV4 and send the action in the body. The predicate matches the action name (not the exact Action=GetCallerIdentity form encoding) so it survives both a raw form-urlencoded body and an api-parsed {"Action":"GetCallerIdentity",...} body.

# a GetCallerIdentity call → 200 STS identity
curl -s -X POST http://localhost:8080/api/ -d 'Action=GetCallerIdentity&Version=2011-06-15'
# {"GetCallerIdentityResponse":{"GetCallerIdentityResult":{"Account":"123456789012","Arn":"arn:aws:iam::123456789012:user/sally","UserId":"AIDAEXAMPLESALLY"},"ResponseMetadata":{"RequestId":"01234567-89ab-cdef-0123-456789abcdef"}}}

The preset is additive — it only calls aux4 mock stub, so it never clears existing stubs. Layer the business endpoints your test exercises on top:

aux4 mock preset aws --port 8080
aux4 mock stub --port 8080 --method POST \
  --path / --when-body-contains ListBuckets \
  --status 200 --body '<ListAllMyBucketsResult>...</ListAllMyBucketsResult>'

Overrides

All optional, with sane defaults, so a test can assert a known identity:

aux4 mock preset aws --port 8080 \
  --user "Devon" --account 999988887777 --userId AIDAEXAMPLEDEVON
  • --user — IAM user name in the caller-identity Arn (default Sally; lowercased with spaces removed, so Sally → sally)
  • --account — AWS account id in the caller identity (default 123456789012)
  • --userId — IAM UserId in the caller identity (default AIDAEXAMPLESALLY)

Also accepts --name and --stateDir to address a server the same way every other aux4/mock command does (precedence: --stateDir > --name > --port).

Base URLs and paths

AWS clients post to a service host root. Point the code-under-test's endpoint at http://localhost:<port>/api and let it post to / — aux4/mock strips the /api mount prefix before matching.

Using in tests

aux4/mock and this preset are plain CLIs, so they drop straight into an aux4/test .test.md. In CI, declare both packages on the test job:

- uses: aux4/action@v1
  with:
    command: test
    packages: aux4/mock,community/mock-preset-aws

This package as a template

community/mock-preset-aws follows the same pattern as community/mock-preset-google, the reference implementation for writing your own community/mock-preset-<service> package: depend on aux4/mock, re-declare the mock profile with a preset routing command, and add a <service> command under mock:preset whose execute is a sequence of aux4 mock stub calls. AWS differs from the OAuth presets in that it matches on the request body (--when-body-contains) rather than a bearer header.