Skip to content

feat(toolkit-lib)!: support custom https.Agent for SDK requests #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,6 @@ const toolkitLib = configureProject(
'glob',
'minimatch',
'p-limit@^3',
'proxy-agent',
'semver',
'split2',
'uuid',
Expand Down
4 changes: 0 additions & 4 deletions packages/@aws-cdk/toolkit-lib/.projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/@aws-cdk/toolkit-lib/.projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { MetadataService } from '@aws-sdk/ec2-metadata-service';
import type { NodeHttpHandlerOptions } from '@smithy/node-http-handler';
import { loadSharedConfigFiles } from '@smithy/shared-ini-file-loader';
import { makeCachingProvider } from './provider-caching';
import { ProxyAgentProvider } from './proxy-agent';
import type { ISdkLogger } from './sdk-logger';
import type { SdkHttpOptions } from './types';
import { AuthenticationError } from '../../toolkit/toolkit-error';
import { IO, type IoHelper } from '../io/private';

Expand Down Expand Up @@ -279,8 +277,3 @@ export function sdkRequestHandler(agent?: Agent): NodeHttpHandlerOptions {
httpAgent: agent,
};
}

export async function makeRequestHandler(ioHelper: IoHelper, options: SdkHttpOptions = {}): Promise<NodeHttpHandlerOptions> {
const agent = await new ProxyAgentProvider(ioHelper).create(options);
return sdkRequestHandler(agent);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from '../proxy-agent';
export * from '../sdk';
export * from '../sdk-provider';
export * from '../sdk-logger';
Expand Down
56 changes: 0 additions & 56 deletions packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/proxy-agent.ts

This file was deleted.

14 changes: 5 additions & 9 deletions packages/@aws-cdk/toolkit-lib/lib/api/aws-auth/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Agent } from 'node:https';
import type { SDKv3CompatibleCredentialProvider } from '@aws-cdk/cli-plugin-contract';
import { AwsCliCompatible } from './awscli-compatible';
import type { SdkProviderServices } from './sdk-provider';
Expand Down Expand Up @@ -32,18 +33,13 @@ export interface SdkConfig {
*/
export interface SdkHttpOptions {
/**
* Proxy address to use
* The agent responsible for making the network requests.
*
* @default No proxy
*/
readonly proxyAddress?: string;

/**
* A path to a certificate bundle that contains a cert to be trusted.
* Use this so set up a proxy connection.
*
* @default No certificate bundle
* @default - uses the shared global node agent
*/
readonly caBundlePath?: string;
readonly agent?: Agent;
}

export abstract class BaseCredentials {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/toolkit-lib/lib/toolkit/toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { type SynthOptions } from '../actions/synth';
import type { WatchOptions } from '../actions/watch';
import { patternsArrayForWatch } from '../actions/watch/private';
import { BaseCredentials, type SdkConfig } from '../api/aws-auth';
import { makeRequestHandler } from '../api/aws-auth/awscli-compatible';
import { sdkRequestHandler } from '../api/aws-auth/awscli-compatible';
import type { SdkProviderServices } from '../api/aws-auth/private';
import { SdkProvider, IoHostSdkLogger } from '../api/aws-auth/private';
import { Bootstrapper } from '../api/bootstrap';
Expand Down Expand Up @@ -185,7 +185,7 @@ export class Toolkit extends CloudAssemblySourceBuilder {
const ioHelper = asIoHelper(this.ioHost, action);
const services: SdkProviderServices = {
ioHelper,
requestHandler: await makeRequestHandler(ioHelper, this.props.sdkConfig?.httpOptions),
requestHandler: sdkRequestHandler(this.props.sdkConfig?.httpOptions?.agent),
logger: new IoHostSdkLogger(ioHelper),
pluginHost: this.pluginHost,
};
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/toolkit-lib/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.