Configuration
The following options may be passed when instantiating the aws-lite
client:
Region / profile config
region
(string)- AWS service region (e.g.
us-west-1
); if not provided, defaults toAWS_REGION
,AWS_DEFAULT_REGION
, orAMAZON_REGION
env vars - By default, a
~/.aws/config
(or custom) file will only be loaded by using theawsConfigFile
config property, or by making theAWS_SDK_LOAD_CONFIG
env var true - Manually specify a config file location with the
awsConfigfile
config property, or with theAWS_CONFIG_FILE
(andAWS_SDK_LOAD_CONFIG
) env var - If
host
is specified,region
can be an arbitrary, non-AWS value; this is helpful when using AWS-compatible APIs - If no region is found,
aws-lite
will throw - Region setting can be overridden per-request
- AWS service region (e.g.
profile
(string)- Selected AWS profile; if not provided, defaults to
AWS_PROFILE
env var, and then to thedefault
profile, if present
- Selected AWS profile; if not provided, defaults to
Credential config
The following settings document basic credential configuration; learn additional details about how aws-lite
implements the credential provider chain.
Credential parameters
accessKeyId
(string)- AWS access key; if not provided, defaults to
AWS_ACCESS_KEY_ID
orAWS_ACCESS_KEY
env vars, and then to a~/.aws/credentials|config
file, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILE
env var - If no access key is found,
aws-lite
will throw
- AWS access key; if not provided, defaults to
secretAccessKey
(string)- AWS secret key; if not provided, defaults to
AWS_SECRET_ACCESS_KEY
orAWS_SECRET_KEY
env vars, and then to a~/.aws/credentials|config
file, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILE
env var - If no secret key is found,
aws-lite
will throw
- AWS secret key; if not provided, defaults to
sessionToken
(string)- AWS session token; if not provided, defaults to
AWS_SESSION_TOKEN
env var, and then to a~/.aws/credentials|config
file, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILE
env var
- AWS session token; if not provided, defaults to
Credential provider chain
imds
(object)- IMDSv2 configuration; accepts two properties:
endpoint
(string) set a custom the IMDSv2 endpoint- If not provided, defaults to
AWS_EC2_METADATA_SERVICE_ENDPOINT
env var, and then to a~/.aws/credentials|config
file’sec2_metadata_service_endpoint
property, if present
- If not provided, defaults to
endpointMode
- (string) set the IMDSv2 host via IP version; eitherIPv4
(which setsendpoint
tohttp://169.254.169.254
, the default), orIPv6
(which sets theendpoint
tohttp://[fd00:ec2::254]
)- If not provided, defaults to
AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE
env var, and then to a~/.aws/credentials|config
file’sec2_metadata_service_endpoint_mode
property, if present
- If not provided, defaults to
- IMDSv2 is enabled by default, but can also be entirely disabled by setting the
AWS_EC2_METADATA_DISABLED
env var
- IMDSv2 configuration; accepts two properties:
General config
autoloadPlugins
(boolean) [default =false
]- Automatically load installed
@aws-lite/*
+aws-lite-plugin-*
plugins; this is not suggested for production use, and should generally only be used for quick local iteration
- Automatically load installed
awsConfigFile
(boolean or string) [default =false
]- Load configuration from an AWS configuration file
- If
true
, it will load from the default (~/.aws/config
) location - If a
string
, it will load from that custom path
awsjsonMarshall
(object)- Lower-level configuration options for marshalling AWS-flavored JSON; reference here
awsjsonUnmarshall
(object)- Lower-level configuration options for unmarshalling AWS-flavored JSON; reference here
debug
(boolean) [default =false
]- Enable debug logging to console
- Can also be enabled by setting the
AWS_LITE_DEBUG
environment variable
keepAlive
(boolean) [default =true
]- Disable Node.js’s connection keep-alive, helpful for local testing
plugins
(array)- Define
aws-lite
plugins for the client instance to use; each plugin must an object or import / require statement. Examples:import dynamodb from '@aws-lite/dynamodb'; await awsLite({ plugins: [ dynamodb ] })
const dynamodb = require('@aws-lite/dynamodb'); await awsLite({ plugins: [ dynamodb ] })
await awsLite({ plugins: [ import('@aws-lite/dynamodb') ] })
await awsLite({ plugins: [ await import('@aws-lite/dynamodb') ] })
await awsLite({ plugins: [ require('@aws-lite/dynamodb') ] })
- Define
responseContentType
(string)- Set an overriding Content-Type header for all responses, helpful for local testing
retries
(number, aliased tomaxAttempts
) [default =5
]- Set the maximum number of graceful retries when API service failures occur; set to
0
to disable retrying
- Set the maximum number of graceful retries when API service failures occur; set to
verifyService
(boolean) [default =true
]- Verify client request
service
names against a list of known AWS services. Iffalse
, anyservice
name will be accepted.
- Verify client request
Endpoint config
Configure custom endpoints for local testing or AWS-compatible APIs. endpoint
is usually the preferred parameter, or use individual properties: pathPrefix
, host
, port
, protocol
.
endpoint
(string, aliased tourl
)- Full URL of the API being requested
- This value should specify the protocol, and if applicable, port and path; example:
http://my-custom-s3-endpoint.net/s3
endpoint
supersedespathPrefix
,host
,port
, andprotocol
; ifendpoint
is specified, the others will be ignored- If a config file is being used (via
awsConfigFile
orAWS_SDK_LOAD_CONFIG
+AWS_CONFIG_FILE
env vars),endpoint
will be assigned theendpoint_url
setting of the specified profile, if present - Alternately,
endpoint
will use the value of theAWS_ENDPOINT_URL
env var, if present
pathPrefix
(string)- Add prefix to any specified paths in all requests, helpful for local testing
host
(string)- Set a custom host name to use, helpful for local testing
- This value should NOT specify a protocol, port, or path; example:
my-custom-s3-endpoint.net
port
(number)- Set a custom port number to use, helpful for local testing
protocol
(string) [default =https
]- Set the connection protocol to
http
, helpful for local testing
- Set the connection protocol to
Example
import awsLite from '@aws-lite/client'
// Load everything from env vars and/or config files
let aws = await awsLite()
// Or specify options
aws = await awsLite({
// Region / profile
region: 'us-west-1',
profile: 'work',
// Credentials
accessKeyId: '$accessKey',
secretAccessKey: '$secretKey',
sessionToken: '$sessionToken',
// Credential provider chain (if above credentials are not passed)
imds: {
endpoint: 'http://[::1]'
endpointMode: 'IPv6', // Overrides `imds.endpoint` if specified
},
// General config
autoloadPlugins: false,
awsConfigFile: '/a/path/to/config',
debug: true,
keepAlive: false,
plugins: [ '@aws-lite/dynamodb', '/a/custom/local/plugin/path' ],
responseContentType: 'application/json',
retries: 4,
// Endpoint config
endpoint: 'http://my-custom-s3-endpoint.net/s3', // Aliased to `url`
// The following options are ignored if `endpoint` is present:
pathPrefix: '/test/path/',
host: 'localhost',
port: 12345,
protocol: 'http',
})
// aws-lite can also be used with AWS-compatible services that use AWS signature v4 (e.g. Backblaze B2)
// Such services can accept alternate credentials passed during instantiation, via env vars, etc.
aws = await awsLite({
accessKeyId: '$alternateAccessKey',
secretAccessKey: '$alternateAccessSecretKey',
region: 'us-west-004',
endpoint: 'https://s3.us-west-004.backblazeb2.com/',
})
Credential provider chain details
To acquire credentials for working with AWS services, aws-lite
supports the standard credential provider chain, and should be generally interoperable with AWS SDK v2 and v3 (with caveats noted below). When an aws-lite
client is initialized, the following credential loading strategy is employed, in order:
- Passed credential parameters
- Environment variables (e.g.
AWS_ACCESS_KEY_ID
, etc.) - SSO
- Requires IAM Identity Center setup, and running AWS CLI:
aws sso login [options]
- Supports standard profiles, and
sso-session
sections inconfig
- Learn more about AWS SSO here
- Requires IAM Identity Center setup, and running AWS CLI:
- Shared
credentials
+config
files (~/.aws/[credentials|config]
)- Supports standard
credentials
profiles, andprofile
sections inconfig
- Supports
AWS_CONFIG_FILE
+AWS_SHARED_CREDENTIALS_FILE
env vars specifying file location, default file location viaAWS_SDK_LOAD_CONFIG
env var, andawsConfigFile
config property; see general configuration options - Learn more about shared
credentials
+config
files here
- Supports standard
- External processes
- IMDSv2
- First, container (ECS) endpoints are checked via
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
, thenAWS_CONTAINER_CREDENTIALS_FULL_URI
environment variables - If ECS is not found, instance (EC2) endpoints are checked via passed
imds
config, then viaAWS_EC2_METADATA_SERVICE_ENDPOINT
+AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE
environment variables, then viaec2_metadata_service_endpoint
+ec2_metadata_service_endpoint_mode
properties in sharedcredentials
+config
files
- First, container (ECS) endpoints are checked via
Credential loading caveats
- IMDSv1 is not currently supported, as it is considered insecure and no longer AWS’s standard version of IMDS
- To improve performance when acquiring IMDSv2 credentials in long-lived processes, IMDSv2 host availability is cached for the duration of the Node.js process; this availability status caching behavior may be changed in the future
- Currently, soon-to-be expired SSO tokens are not automatically refreshed by
aws-lite
; PRs are welcome should the community deem this a necessary feature - Assuming IAM roles via OAuth 2.0 access token or OIDC token files is not currently supported; PRs are welcome should the community deem this a necessary feature
- The following credential providers cannot be used in Lambda environments: SSO, shared
credentials
+config
files, external processes, and IMDSv2
Additional credential resource provider chain resources: