Check the way to AWS
$ grim infra:doctor
Run this before your first infra:aws-* command on a machine, and again whenever one of them stops with Required tools are missing or AWS CLI is not authenticated. Those wizards give up at the first missing piece. grim infra:doctor looks at all the pieces, creates nothing, and tells you how to get each missing one.
It is also the way back in after months away, when you no longer remember which profile belongs to which account.
Usage
$ grim infra:doctor # tools, credentials, default region
$ grim infra:doctor --profile=acme --region=eu-west-1 # another profile, another region
$ grim infra:doctor --guide # the full setup guide, even when all is wellRun it from anywhere. It reads your AWS configuration and makes a few read-only calls. It is a different command from grim doctor, which checks a local development machine.
Arguments and options
Diagnose AWS infra prerequisites and walk through credential setup
Usage
grim infra:doctor [--region REGION] [--profile PROFILE] [--guide]Options
| Option | Description |
|---|---|
--region=REGION |
Region to verify default VPC presence in (default: eu-central-1) |
--profile=PROFILE |
AWS CLI profile to test |
--guide |
Always print the full setup guide (otherwise only failed sections show fixes) |
What it actually does
- Looks for the tools.
awsandterraform, each with its version and path, ornot installed. - Checks the credentials. Asks AWS who you are with the default profile or
--profile, and prints the account, its alias, the ARN and the profile. When the alias cannot be read it says so and moves on; the wizards do not need it. - Checks the region. Only when step 2 passed: whether regions can be listed, and whether
eu-central-1or--regionhas a default VPC.grim infra:aws-ec2places its server there and refuses a region without one. - Lists the local AWS profiles and marks the one
AWS_PROFILEselects. - Prints a verdict.
Everything looks good.with the next command to run, or a setup guide for the parts that failed.
The exit code is 0 when both tools are there and the credentials work, and 1 otherwise. A missing default VPC is reported in step 3 and does not change it.
The setup guide
Each failed part brings its own section, and --guide prints them all.
| Missing | The guide gives you |
|---|---|
aws CLI |
Install commands for macOS, Linux and Windows |
terraform |
The same |
| Working credentials | Two routes: an IAM user with an access key and aws configure, or AWS SSO with aws configure sso and aws sso login |
| Permissions | An IAM policy to paste as an inline policy on that user |
The policy is broad on purpose: all of EC2, S3, IAM, CloudTrail, CloudWatch, SNS and Budgets, plus reading SSM parameters and the caller identity. That is what creating and removing everything in the family takes. The guide says so itself, and tells you to tighten it if your organisation requires least privilege.
Where the family keeps its records
Nothing is stored in a cloud backend. What the wizards know lives in two places under your home directory.
| Path | Holds |
|---|---|
~/.grim/servers.json |
Each server with its infra block, and an aws_resources section for buckets, trails, alarm sets and budgets |
~/.grim/infra/<id>/ |
The Terraform files, variables and state of one stack, snapshots of the state taken before each change, and a generated SSH key if you asked for one |
~/.grim/infra/_archived/ |
The directories of destroyed stacks, moved there by grim infra:destroy |
Back these up with the rest of your home directory. On a new machine without them grim cannot remove what it created. The resources are still findable in the AWS console by their tag ManagedBy=grim-cli.
Pitfalls
An SSO session has run out
A profile that worked last week fails the credentials check with AWS's own expiry message. Nothing is broken. Run aws sso login --profile=acme and run the check again.
The check passes and a wizard still fails on permissions
grim infra:doctor proves who you are and that you may list regions. It does not try to create anything, so a policy that is too narrow only shows when Terraform hits the refused call. Compare the user's policy with the one from --guide.
After it finishes
With everything found, the last lines name the next step. On an account with nothing in it yet, a sensible order is the budget first, then the trail, then the server.
$ grim infra:aws-budget --limit=50 --email=ops@example.com
$ grim infra:aws-cloudtrail --preset=minimal
$ grim infra:aws-ec2grim infra:aws-budget is free and warns you about everything that follows. grim infra:aws-cloudtrail records who did what from then on.
Related spells
grim infra:list
Survey what runs on AWS
List every server and AWS resource grim has created, with a monthly cost estimate for each and the ids that infra:destroy takes.
grim infra:dns
Point a domain at a server
Print the two DNS records that point a domain at a server, with step-by-step instructions for Cloudflare or Route 53, and check whether they are live yet.
grim infra:destroy
Unmake what grim made
Remove a server or AWS resource that grim created, after checking the account and making you type its name, and stop it from being billed.
grim infra:aws-ec2
Raise a server on AWS
Create one EC2 instance with a static address, a firewall and your SSH key in your AWS account, then hand it to grim server:setup.
grim infra:aws-budget
Set a spending alarm
Create a monthly AWS budget that mails you at 50, 80 and 100 percent of a limit, and when AWS forecasts the month will end above it.
grim doctor
Check your circle
Check every tool grim expects on this machine, and the project you are standing in, and say what to do about what is missing.