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_REGIONenv vars - By default, a
~/.aws/config(or custom) file will only be loaded by using theawsConfigFileconfig property, or by making theAWS_SDK_LOAD_CONFIGenv var true - Manually specify a config file location with the
awsConfigfileconfig property, or with theAWS_CONFIG_FILE(andAWS_SDK_LOAD_CONFIG) env var - If
hostis specified,regioncan be an arbitrary, non-AWS value; this is helpful when using AWS-compatible APIs - If no region is found,
aws-litewill throw - Region setting can be overridden per-request
- AWS service region (e.g.
profile(string)- Selected AWS profile; if not provided, defaults to
AWS_PROFILEenv var, and then to thedefaultprofile, 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_IDorAWS_ACCESS_KEYenv vars, and then to a~/.aws/credentials|configfile, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILEenv var - If no access key is found,
aws-litewill throw
- AWS access key; if not provided, defaults to
secretAccessKey(string)- AWS secret key; if not provided, defaults to
AWS_SECRET_ACCESS_KEYorAWS_SECRET_KEYenv vars, and then to a~/.aws/credentials|configfile, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILEenv var - If no secret key is found,
aws-litewill throw
- AWS secret key; if not provided, defaults to
sessionToken(string)- AWS session token; if not provided, defaults to
AWS_SESSION_TOKENenv var, and then to a~/.aws/credentials|configfile, if present - Manually specify a credentials file location with the
AWS_SHARED_CREDENTIALS_FILEenv 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_ENDPOINTenv var, and then to a~/.aws/credentials|configfile’sec2_metadata_service_endpointproperty, if present
- If not provided, defaults to
endpointMode- (string) set the IMDSv2 host via IP version; eitherIPv4(which setsendpointtohttp://169.254.169.254, the default), orIPv6(which sets theendpointtohttp://[fd00:ec2::254])- If not provided, defaults to
AWS_EC2_METADATA_SERVICE_ENDPOINT_MODEenv var, and then to a~/.aws/credentials|configfile’sec2_metadata_service_endpoint_modeproperty, if present
- If not provided, defaults to
- IMDSv2 is enabled by default, but can also be entirely disabled by setting the
AWS_EC2_METADATA_DISABLEDenv 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_DEBUGenvironment variable
keepAlive(boolean) [default =true]- Disable Node.js’s connection keep-alive, helpful for local testing
plugins(array)- Define
aws-liteplugins 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
0to disable retrying
- Set the maximum number of graceful retries when API service failures occur; set to
verifyService(boolean) [default =true]- Verify client request
servicenames against a list of known AWS services. Iffalse, anyservicename 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 endpointsupersedespathPrefix,host,port, andprotocol; ifendpointis specified, the others will be ignored- If a config file is being used (via
awsConfigFileorAWS_SDK_LOAD_CONFIG+AWS_CONFIG_FILEenv vars),endpointwill be assigned theendpoint_urlsetting of the specified profile, if present - Alternately,
endpointwill use the value of theAWS_ENDPOINT_URLenv 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-sessionsections inconfig - Learn more about AWS SSO here
- Requires IAM Identity Center setup, and running AWS CLI:
- Shared
credentials+configfiles (~/.aws/[credentials|config])- Supports standard
credentialsprofiles, andprofilesections inconfig - Supports
AWS_CONFIG_FILE+AWS_SHARED_CREDENTIALS_FILEenv vars specifying file location, default file location viaAWS_SDK_LOAD_CONFIGenv var, andawsConfigFileconfig property; see general configuration options - Learn more about shared
credentials+configfiles here
- Supports standard
- External processes
- IMDSv2
- First, container (ECS) endpoints are checked via
AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, thenAWS_CONTAINER_CREDENTIALS_FULL_URIenvironment variables - If ECS is not found, instance (EC2) endpoints are checked via passed
imdsconfig, then viaAWS_EC2_METADATA_SERVICE_ENDPOINT+AWS_EC2_METADATA_SERVICE_ENDPOINT_MODEenvironment variables, then viaec2_metadata_service_endpoint+ec2_metadata_service_endpoint_modeproperties in sharedcredentials+configfiles
- 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+configfiles, external processes, and IMDSv2
Additional credential resource provider chain resources: