Skip to content
Ingrid Kovarová

Dec 5, 202614 min read

To call AWS APIs from a terminal with aws <service> <command>, you use AWS CLI v2, AWS's free, open-source tool. The tool costs nothing; you pay for whatever the calls create or use.

Call AWS APIs from the CLI

What the CLI does and what it costs

Underneath, every command is a thin wrapper over a service API. aws s3 ls and aws ec2 describe-instances send the same requests your code would send through an SDK. They're signed with whichever credentials the CLI finds.

Modal dialog for enabling OpenAI as an AI provider in Activepieces Platform Admin, showing API key setup instructions and…

When the CLI runs inside a workflow platform, the question becomes who holds the keys it signs with.

Activepieces can route every credential it touches, from API keys and OAuth tokens to the connection secrets behind each app, to your own secret manager, in the self-hosted edition and the enterprise cloud tier alike.

Point a self-hosted instance at one and the Activepieces database holds none of them, and the same secret-manager integration sits in the enterprise governance set beside SCIM, custom RBAC, SSO/SAML and audit logs. Your credentials are never ours to hold.

Activepieces admin panel showing Single Sign On configuration options including Allowed Domains, Google, SAML 2.0, and…

AWS CLI version 2 vs version 1

Version 2 is the current major release, and the differences that matter in operations are retry behaviour and how it gets onto a machine.

AWS CLI v1 AWS CLI v2
Default retry mode Legacy Standard
Default max attempts Set by legacy mode Set by standard mode
Install method Python package manager Official installer for your operating system
Python dependency Needs a Python installation Bundles its own

Pin the version on build agents and scheduled hosts, and print it in job logs.

Everything below works on Activepieces' free plan. Start without code or a credit card.

Install AWS CLI on each platform

Install v2 with your platform's own installer, then run aws --version before anything else. An older v1 earlier on PATH is the usual reason a machine behaves differently from the one you tested on.

The commands below follow the AWS CLI v2 install guide, as checked on 5 December 2026.

On macOS, download the package and run the system installer:

curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg ./AWSCLIV2.pkg -target /

Install AWS CLI on Linux (x86_64 and ARM)

Run the four steps below to put v2 under /usr/local/aws-cli and link aws into /usr/local/bin:

  1. curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
  2. unzip awscliv2.zip
  3. sudo ./aws/install
  4. aws --version

On ARM, change only the download URL to https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip; the other steps are identical. To update later, rerun the installer with --update.

On Windows, run the MSI installer from a command prompt:

msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi

Add /qn for a silent install in scripted builds. Rerunning the MSI updates the install.

Verify the install and fix PATH problems

If aws --version prints aws-cli/1, v1 is shadowing v2; it should print a version starting with aws-cli/2.

List every copy with which -a aws (on Windows, where aws), then remove the old one, for example with pip uninstall awscli, and run hash -r or open a new shell.

If aws isn't found at all, add /usr/local/bin to PATH.

Sign in using SSO or access keys

Use IAM Identity Center first, because its credentials expire on their own and nobody has to remember to rotate them.

Compare the three options on lifetime, setup effort, leak risk and CI fit in the table. The option with the most setup is also the one with the least to leak.

Option Credential lifetime Setup effort Leak risk CI fit
IAM Identity Center SSO Short sessions, 15 minutes to 12 hours Highest: one-time org setup, then aws configure sso Low Poor for unattended jobs; good for people
IAM user access keys Until someone rotates or deletes them Lowest High Works, but a leaked key stays valid
Environment variables with an assumed role 15 minutes to 12 hours Moderate Low to medium Best for pipelines

For IAM Identity Center (SSO), run aws configure sso once to define a profile, then aws sso login when the session lapses. The token is cached locally and the CLI fetches role credentials from it on demand.

A key committed to a repository in 2023 still works until someone deletes it, which is why IAM user access keys are the weakest habit here. Keep them only for tools that can't do anything better, and put a named owner on each one.

A repository folder with a single IAM user access key tag attached to an old commit, and a hand reaching to delete it.

AWS CLI environment variables and assumed roles

Set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN from an assumed role. Per the AWS IAM User Guide, AssumeRole sessions can last up to 12 hours, so a stolen token from a long job still dies the same day.

When one role assumes another, which is role chaining, the session is capped at 1 hour, so a pipeline that hops through two roles must renew mid-run or fail partway.

With GetSessionToken, which issues temporary credentials for an IAM user, a token can live up to 36 hours.

How long short-lived AWS credentials can last

For configuration, profiles live in ~/.aws/config and ~/.aws/credentials. Select one with AWS_PROFILE, and set the region with AWS_REGION or region in the profile.

Environment variables beat profile settings, so a stale AWS_ACCESS_KEY_ID in a shell silently overrides your SSO login. When the identity looks wrong, run aws sts get-caller-identity before anything else.

Essential AWS CLI commands

Memorise sts get-caller-identity, s3 ls, cp and sync, ec2 describe-instances, lambda invoke, logs tail and cloudformation deploy. Add the --query and --output flags, which make their results usable in scripts.

Verify AWS CLI credentials with get-caller-identity

aws sts get-caller-identity

It returns the account, the user or role ARN and the user ID behind your credentials. It needs no special permission, so a failure here is a credentials or region problem, not a policy one.

Storage and compute commands

aws s3 ls s3://my-bucket/reports/
aws s3 cp ./build.zip s3://my-bucket/releases/build.zip
aws s3 sync ./site s3://my-bucket/site --delete
aws ec2 describe-instances --region eu-west-1
aws lambda invoke --function-name my-fn \
 --payload '{"id":"42"}' \
 --cli-binary-format raw-in-base64-out out.json
aws logs tail /aws/lambda/my-fn --follow --since 1h
aws cloudformation deploy --template-file template.yaml \
 --stack-name my-stack --capabilities CAPABILITY_IAM

Rehearse sync with --delete using --dryrun first, because it removes destination files that no longer exist locally. describe-instances shows only the region you point it at, which is why an "empty" result is often the wrong region.

A terminal showing an aws s3 sync command with --delete and --dryrun, beside a local site folder with fewer files and an s3…

AWS CLI output, query and pagination options

aws ec2 describe-instances \
 --query 'Reservations[].Instances[].InstanceId' \
 --output text
aws s3api list-objects-v2 --bucket my-bucket --max-items 100

Even with --query, the full response still travels over the wire, since the JMESPath filter is applied on the client. --output takes json, table, text or yaml. Use text for shell variables and json for anything that feeds another tool.

Easier to see it running than to read about it: set it up free, no card.

Fix AWS CLI errors in production

The table lists the eight errors you'll meet most, with the usual cause and the first fix to try, so whoever owns the job can triage without reading a stack trace.

Error Cause Fix
Unable to locate credentials No profile, environment variables or role reach the process Run aws configure list, then set a profile or attach a role
ExpiredToken The session token or SSO session has lapsed Run aws sso login, or re-issue the temporary credentials
InvalidClientTokenId The access key ID is deleted, mistyped or from another account Replace it with a current key, or switch to a role
SignatureDoesNotMatch The secret key is wrong, or the request was signed with a bad clock Re-enter the secret without stray whitespace and correct the system clock
AccessDenied The identity is valid but its policy doesn't allow the action Add the named action to the role's policy
Region mismatch The resource lives in a different region from the one the CLI targets Pass --region or set the profile's region
command not found The CLI isn't installed, or its directory is not on PATH Reinstall and fix PATH
Proxy or certificate error A corporate proxy intercepts TLS and its certificate is untrusted Point AWS_CA_BUNDLE at the proxy's certificate

Run aws sts get-caller-identity first in any of these cases, because it shows which identity the CLI actually believes it's.

If you see AccessDenied, authentication worked, so don't rotate keys. Read the message, find the denied action, and change the policy.

If you see AccessDenied, authentication worked, so don't rotate keys.

Handle AWS CLI rate limits and throttling

Put retry settings in that same image or runner. The CLI has no rate limit of its own: limits are set per service, per account and per Region, so the throttling that pages someone at 2am comes from the service, not the tool.

There are three retry modes in the CLI: legacy, standard and adaptive. Version 1 defaults to legacy, which allows 4 retries (5 calls in total).

Version 2 defaults to standard, which allows 2 retries (3 calls in total).

Set the behaviour explicitly rather than trusting the default. AWS_RETRY_MODE and AWS_MAX_ATTEMPTS override it per environment, and retry_mode and max_attempts do the same in the config file.

AWS_MAX_ATTEMPTS counts the first call, so a value of 3 means two retries. Adaptive mode adds client-side rate limiting and suits one caller hammering one throttled service. It isn't a fix for many jobs sharing a quota.

Default AWS request limits by service

Find AWS API rate limits per service

Look at the defaults and they differ by orders of magnitude. AWS documents 11,000 read requests per second for S3 and 3,500 writes, so a bulk upload throttles long before a bulk download does.

STS allows 600 requests per second, which matters when many jobs assume roles at the same moment. SSM GetParameter allows only 40 per second, so a fleet that reads secrets at startup can exhaust it at once.

Two pipes: a wide STS pipe with many job boxes passing through, and a narrow SSM GetParameter pipe with a fleet of servers…

These were the published defaults on 2026-12-05, and your account may differ. For your own limits, run aws service-quotas list-service-quotas --service-code ssm.

Handle AWS CLI throttling in scripts

When a call is throttled, it surfaces as ThrottlingException, RequestLimitExceeded or, on S3, SlowDown. Treat each as a signal to slow down, not as a failure.

Stagger scheduled jobs, cache values such as parameters instead of refetching them, and let the retry mode back off. If a job still fails after its retries, it should exit non-zero with the error text.

Run AWS CLI in CI and scheduling

Give the job a role it assumes at run time through OpenID Connect (OIDC), not a stored access key. Make the job's exit code the signal that someone gets told.

  1. Create an OIDC identity provider in IAM for your CI system.
  2. Create a role whose trust policy accepts tokens from that provider for one repository only.
  3. Attach a least-privilege policy listing just the actions and resources the job needs.
  4. Assume the role in the job, using your CI provider's AWS credentials step or aws sts assume-role-with-web-identity.
  5. Run aws with --no-cli-pager, so output never waits on a pager nobody's there to dismiss.
  6. Check the exit code, and fail the job on anything non-zero.

If step 2 trusts a whole organisation instead of one repository, every repository in it can assume the role.

Schedule AWS CLI jobs with cron or EventBridge

Use cron on a host you already maintain, or EventBridge Scheduler, AWS's managed scheduler, if you want no host at all. Either way, name an owner for the schedule before it ships.

Capture stderr and the exit code, because a scheduler that swallows both reports success on a failed run.

What Activepieces does about this

Activepieces is an open-source automation tool, and its community edition is MIT-licensed, so you can read the code that handles your credentials.

For the simple jobs this article mentions, such as putting a file into S3 or a message on an SQS queue, you build the flow as a workflow instead of a shell script on a cron host.

Activepieces workflow builder with HTTP request step selected and its settings panel open showing method, URL, headers, and…

There are no aws binaries to pin, no PATH to repair and no retry environment variables to remember on each runner.

The credential problem doesn't go away, it moves, so the same rules apply. Each AWS step runs against a stored connection, and that connection should belong to a dedicated identity whose policy lists only the actions the flow needs.

Give each flow its own identity and name an owner for it, exactly as you would for an IAM user key. If an AccessDenied shows up in a run, you read the denied action and fix the policy, the same as at the terminal.

Where the secrets live is the part we control. On a self-hosted instance, or the enterprise cloud tier, you can point Activepieces at your own secret manager so the connection values never sit in our database.

That feature ships alongside SSO/SAML, SCIM, custom RBAC and audit logs, so you can see who ran a flow and which connection it used.

For anything the integrations don't cover, keep the CLI in your image and call it from a flow, with the exit-code and stderr rules from the CI section unchanged.

Frequently asked questions

Once something has already failed, these are the questions the next person on call asks first.

Is the AWS CLI free to use? Yes, the tool itself costs nothing to download or run.

You pay for what the commands create or call, so a stray run-instances in a forgotten script becomes a bill, and the owner of that account is the one who sees it.

Should I use AWS CLI v1 or v2 in 2026? Use v2 for anything new. It ships as a standalone installer and supports single sign-on login directly, which fits the short-lived credentials this article recommends.

Keep v1 only where an existing pipeline depends on it, and write down who'll migrate it.

How do I switch between multiple AWS accounts? Define a named profile for each account, then select one with --profile name on a single command or AWS_PROFILE=name for a whole shell session.

Run aws sts get-caller-identity before anything destructive. It prints the account and role you're about to act as, which settles the question of which account you're in.

How do I update the AWS CLI?

Re-run the installer for your platform. On Linux, run the v2 install script again with the update option. On macOS and Windows, run the current package installer over the existing one.

Check the result with aws --version. A v1 install managed by pip is upgraded with pip instead. In a CI image, pin the version deliberately so a job doesn't change behaviour overnight.

Can I use the AWS CLI without an AWS account? Only for local things. aws --version, aws help and aws configure run offline.

Any command that calls a service needs credentials tied to an account, even if it only reads, so a contractor without access can install the tool but can't do anything with it.

Share

Get started

Automate this without code.

Cloud or your own servers.

Start free Talk to sales