Skip to content

Commit 10b0455

Browse files
authored
fix(lambda appbuilder): v3 client use toolkit cred
## Problem two v3 client are not using toolkit credentials ## Solution Add toolkit credential to v3 client
1 parent 53c4c09 commit 10b0455

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

packages/core/src/awsService/appBuilder/explorer/nodes/deployedNode.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
s3BucketType,
2929
} from '../../../../shared/cloudformation/cloudformation'
3030
import { ToolkitError } from '../../../../shared'
31+
import { getIAMConnection } from '../../../../auth/utils'
3132

3233
const localize = nls.loadMessageBundle()
3334
export interface DeployedResource {
@@ -100,7 +101,20 @@ export async function generateDeployedNode(
100101
code: 'lambdaClientError',
101102
})
102103
}
103-
const v3Client = new LambdaClient({ region: regionCode })
104+
const connection = await getIAMConnection({ prompt: false })
105+
if (!connection || connection.type !== 'iam') {
106+
return [
107+
createPlaceholderItem(
108+
localize(
109+
'AWS.appBuilder.explorerNode.unavailableDeployedResource',
110+
'[Failed to retrive deployed resource.]'
111+
)
112+
),
113+
]
114+
}
115+
const cred = await connection.getCredentials()
116+
const v3Client = new LambdaClient({ region: regionCode, credentials: cred })
117+
104118
const v3command = new GetFunctionCommand({ FunctionName: deployedResource.PhysicalResourceId })
105119
try {
106120
v3configuration = (await v3Client.send(v3command)).Configuration as FunctionConfiguration

packages/core/src/awsService/appBuilder/explorer/nodes/deployedStack.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TreeNode } from '../../../../shared/treeview/resourceTreeDataProvider'
77
import { getIcon } from '../../../../shared/icons'
88
import { CloudFormationClient, DescribeStacksCommand } from '@aws-sdk/client-cloudformation'
99
import { ToolkitError } from '../../../../shared'
10+
import { getIAMConnection } from '../../../../auth/utils'
1011

1112
export class StackNameNode implements TreeNode {
1213
public readonly id = this.stackName
@@ -40,7 +41,12 @@ export class StackNameNode implements TreeNode {
4041
}
4142

4243
export async function generateStackNode(stackName?: string, regionCode?: string): Promise<StackNameNode[]> {
43-
const client = new CloudFormationClient({ region: regionCode })
44+
const connection = await getIAMConnection({ prompt: false })
45+
if (!connection || connection.type !== 'iam') {
46+
return []
47+
}
48+
const cred = await connection.getCredentials()
49+
const client = new CloudFormationClient({ region: regionCode, credentials: cred })
4450
try {
4551
const command = new DescribeStacksCommand({ StackName: stackName })
4652
const response = await client.send(command)

packages/core/src/test/shared/applicationBuilder/explorer/nodes/deployedNode.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { getIcon } from '../../../../../shared/icons'
2424
import _ from 'lodash'
2525
import { isTreeNode } from '../../../../../shared/treeview/resourceTreeDataProvider'
2626
import { Any } from '../../../../../shared/utilities/typeConstructors'
27+
import { IamConnection, ProfileMetadata } from '../../../../../auth/connection'
28+
import * as AuthUtils from '../../../../../auth/utils'
2729

2830
describe('DeployedResourceNode', () => {
2931
const expectedStackName = 'myStack'
@@ -138,6 +140,13 @@ describe('generateDeployedNode', () => {
138140
describe('LambdaFunctionNode', () => {
139141
let mockDefaultLambdaClientInstance: sinon.SinonStubbedInstance<LambdaClientModule.DefaultLambdaClient>
140142
let mockLambdaNodeInstance: sinon.SinonStubbedInstance<LambdaNodeModule.LambdaNode>
143+
const iamConnection: IamConnection & { readonly state: ProfileMetadata['connectionState'] } = {
144+
type: 'iam',
145+
id: '0',
146+
label: 'iam',
147+
getCredentials: sinon.stub(),
148+
state: 'valid',
149+
}
141150

142151
const lambdaDeployedNodeInput = {
143152
deployedResource: {
@@ -158,6 +167,7 @@ describe('generateDeployedNode', () => {
158167
// Stub the constructor of LambdaNode to return stub instance
159168
mockLambdaNodeInstance = sandbox.createStubInstance(LambdaNodeModule.LambdaNode)
160169
sandbox.stub(LambdaNodeModule, 'LambdaNode').returns(mockLambdaNodeInstance)
170+
sandbox.stub(AuthUtils, 'getIAMConnection').resolves(iamConnection)
161171
})
162172

163173
it('should return a DeployedResourceNode for valid Lambda function happy path', async () => {

0 commit comments

Comments
 (0)