Skip to content
Get Started for Free

Multi-Account Setups

LocalStack ships with multi-account support which allows namespacing based on AWS account ID.

LocalStack uses the value in the AWS Access Key ID field for the purpose of namespacing over account ID. For more information, see Credentials.

The Access Key ID field can be configured in the AWS CLI in multiple ways: please refer to AWS CLI documentation.

In the following examples, we select the account ID with the --account flag of lstk aws.

Terminal window
lstk aws --account 000000000001 ec2 create-key-pair --key-name green-hospital
lstk aws --account 000000000002 ec2 create-key-pair --key-name red-medicine
lstk aws --account 000000000001 ec2 describe-key-pairs
{
"KeyPairs": [
{
"KeyFingerprint": "6b:e3:a3:41:4b:60:f3:6d:7b:84:3e:17:e3:ad:d0:15",
"KeyName": "green-hospital"
}
]
}
lstk aws --account 000000000002 ec2 describe-key-pairs
{
"KeyPairs": [
{
"KeyFingerprint": "16:4c:64:13:36:41:7c:75:d0:51:f0:db:ed:d7:c8:95",
"KeyName": "red-medicine"
}
]
}

Alternatively, you can set the account ID through the AWS_ACCESS_KEY_ID environment variable:

Terminal window
AWS_ACCESS_KEY_ID=000000000001 lstk aws ec2 describe-key-pairs

If no explicit Account ID is set, LocalStack falls back to default. In this example, no resources are returned.

Terminal window
lstk aws ec2 describe-key-pairs
{
"KeyPairs": []
}
Was this page helpful?