Skip to content

Commit

Permalink
fix(cli): CLI does not use regional endpoints (#9835)
Browse files Browse the repository at this point in the history
Make CLI and `cdk-assets` use regional endpoints by setting
`AWS_STS_REGIONAL_ENDPOINTS=regional`.

While we are configuring the SDK by setting global environment
variables anyway (*shudder*), might as well improve performance
a bit by enabling keepalive on the connections (by setting
`AWS_NODEJS_CONNECTION_REUSE_ENABLED=1`).

Fixes #9223.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr committed Aug 19, 2020
1 parent dfe2c5c commit 34450b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/aws-cdk/lib/api/aws-auth/sdk-provider.ts
Expand Up @@ -12,6 +12,12 @@ import { Mode } from '../aws-auth/credentials';
import { AwsCliCompatible } from './awscli-compatible';
import { ISDK, SDK } from './sdk';


// Some configuration that can only be achieved by setting
// environment variables.
process.env.AWS_STS_REGIONAL_ENDPOINTS = 'regional';
process.env.AWS_NODEJS_CONNECTION_REUSE_ENABLED = '1';

/**
* Options for the default SDK provider
*/
Expand Down Expand Up @@ -82,7 +88,7 @@ const CACHED_DEFAULT_CREDENTIALS = Symbol('cached_default_credentials');
*/
export class SdkProvider {
/**
* Create a new SdkProvider which gets its defaults in a way that haves like the AWS CLI does
* Create a new SdkProvider which gets its defaults in a way that behaves like the AWS CLI does
*
* The AWS SDK for JS behaves slightly differently from the AWS CLI in a number of ways; see the
* class `AwsCliCompatible` for the details.
Expand Down Expand Up @@ -302,6 +308,7 @@ function parseHttpOptions(options: SdkHttpOptions) {
debug('Using CA bundle path: %s', caBundlePath);
config.httpOptions.agent = new https.Agent({
ca: readIfPossible(caBundlePath),
keepAlive: true,
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/cdk-assets/bin/publish.ts
Expand Up @@ -67,6 +67,8 @@ class DefaultAwsClient implements IAws {
constructor(profile?: string) {
// Force AWS SDK to look in ~/.aws/credentials and potentially use the configured profile.
process.env.AWS_SDK_LOAD_CONFIG = '1';
process.env.AWS_STS_REGIONAL_ENDPOINTS = 'regional';
process.env.AWS_NODEJS_CONNECTION_REUSE_ENABLED = '1';
if (profile) {
process.env.AWS_PROFILE = profile;
}
Expand Down

0 comments on commit 34450b0

Please sign in to comment.