Skip to content

Commit

Permalink
fix: provide region to AWS SDK client from config file (#67)
Browse files Browse the repository at this point in the history
* fix: provide region to AWS SDK client from config file

* add changeset
  • Loading branch information
fossamagna authored Aug 2, 2024
1 parent 46a01f7 commit d4f9f30
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-owls-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"amplify-backend-vscode": patch
---

fix: provide region to AWS SDK client from config file
13 changes: 11 additions & 2 deletions src/auth/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as vscode from "vscode";
import { loadSharedConfigFiles } from "@smithy/shared-ini-file-loader";
import {
loadSharedConfigFiles,
DEFAULT_PROFILE,
} from "@smithy/shared-ini-file-loader";

class Auth {
static readonly instance = new Auth();

private profile: string = "default";
private profile: string = DEFAULT_PROFILE;

private _onDidChangeProfile: vscode.EventEmitter<string | undefined | void> =
new vscode.EventEmitter<string | undefined | void>();
Expand Down Expand Up @@ -36,6 +39,12 @@ class Auth {
this.profile = profile;
this._onDidChangeProfile.fire(profile);
}

async getRegion(profile?: string) {
const sharedConfigFiles = await loadSharedConfigFiles();
const iniSection = sharedConfigFiles.configFile[profile ?? this.profile];
return iniSection.region;
}
}

export default Auth;
5 changes: 4 additions & 1 deletion src/explorer/amplify-backend-tree-data-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ export class AmplifyBackendTreeDataProvider
private async getStackResources(
stackName: string
): Promise<AmplifyBackendBaseNode[]> {
const profile = Auth.instance.getProfile();
const credentials = fromIni({
profile: Auth.instance.getProfile(),
profile,
});
const region = await Auth.instance.getRegion(profile);
const client = new CloudFormationClient({
credentials,
region,
});
const input = {
StackName: stackName,
Expand Down

0 comments on commit d4f9f30

Please sign in to comment.