Is there any way to specify --endpoint-url in aws cli config file
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Yes, you can avoid repeating --endpoint-url on every AWS CLI command by using configuration-based endpoint settings. This is especially useful for LocalStack, private service endpoints, and isolated test environments. The exact setup depends on CLI version and whether you want global, profile-specific, or service-specific behavior.
Why Endpoint Configuration Matters
Custom endpoints are common when:
- testing against LocalStack
- using private VPC endpoints in constrained networks
- connecting to compatible APIs in non-default environments
Hardcoding endpoint flags in scripts is fragile and error-prone. Config files reduce duplication and keep behavior consistent.
Config File Locations and Profiles
AWS CLI reads configuration from user-level files unless overridden by environment variables.
Typical paths:
- Linux and macOS:
~/.aws/config - Windows:
%UserProfile%\\.aws\\config
Keep endpoint settings in a dedicated profile so you can switch targets safely without changing every command.
Profile-Based Configuration Example
In your AWS config file, define a profile and service endpoint mapping.
With this profile, commands can target LocalStack without passing endpoint flags repeatedly.
Environment Variable Alternative
For one service or one script execution context, environment variables can be simpler.
This works well in short-lived shell sessions and CI jobs.
Service-Specific Overrides in Scripts
Even with config defaults, explicit flags still override settings when needed.
Use this sparingly for debugging or temporary endpoint experiments.
Validate Effective Configuration
When debugging endpoint behavior, inspect active config values and command outputs.
--debug is useful because request logs reveal which endpoint URL was actually used.
CI and Team Workflow Recommendations
Store environment-specific endpoint choices in profile files or CI environment variables, not scattered command flags. Keep one profile per environment and document expected endpoint matrix in repository docs.
For CI, inject endpoint values through secure pipeline configuration so scripts remain portable between local and automated runs. This also reduces the chance of accidentally calling production endpoints during integration tests.
Safety Checks Before Running Commands
When using custom endpoints, run non-destructive commands first, such as list or describe operations. Confirm account identity, region, and endpoint host before write actions.
A simple preflight pattern can prevent destructive mistakes in mixed local and production shells.
Local Development Pattern
A practical pattern is to keep one profile dedicated to local emulation and one profile for real cloud access. Use shell aliases that always include --profile so command history stays explicit. This reduces accidental cross-environment operations and makes troubleshooting easier because endpoint intent is visible in every invocation. It also makes onboarding checklists easier for new team members.
Common Pitfalls
- Mixing profile endpoint settings and manual flags can produce confusing overrides.
- Forgetting to switch profile leads to requests hitting real AWS unintentionally.
- Assuming one endpoint applies to all services when only selected services were configured.
- Committing local endpoint config with production credentials can create risk.
- Debugging failures without
--debugoutput often hides the true endpoint used.
Summary
- AWS CLI endpoint behavior can be configured to reduce repeated
--endpoint-urlflags. - Use profile and service config blocks for stable multi-command workflows.
- Use environment variables for temporary or CI-specific endpoint routing.
- Keep explicit command-line overrides for targeted troubleshooting.
- Validate active endpoint resolution with
aws configure listand debug logs.

