Skip to content

Cannot use aws component with config using sdk v3.668.0 : Can not add runtime configuration property: \"$source\". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set #6951

@Thybat

Description

@Thybat

Checkboxes for prior research

Describe the bug

This issue happens when trying to access an aws component using 'config' lib to create it with the constructor.

It produces the following error : "Can not add runtime configuration property: "$source". Configuration objects are immutable unless ALLOW_CONFIG_MUTATIONS is set."

Config version is 3.3.12

SDK version is 3.668.0

This is working fine with 3.654.0 version of the SDK

Using the object directly works fine

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

"@aws-sdk/client-dynamodb": "3.668.0", "@aws-sdk/client-sqs": "3.668.0", "@aws-sdk/lib-dynamodb": "3.668.0"

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v22.11.0

Reproduction Steps

config dev

"aws": {
        "region": "eu-west-1",
        "endpoint": "http://localhost:4569",
        "credentials": {
          "accessKeyId": "d",
          "secretAccessKey": "d"
        }
    }
Repo.ts

import { Service } from 'typedi';
import {
  DeleteCommand, DynamoDBDocumentClient,
} from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import config from 'config';


@Service()
export default class Repo{
  private dynamodbClient: DynamoDBDocumentClient;
  private TABLE_NAME = `ddb-${process.env.NODE_ENV}`;

  constructor() {
    awsConfig = config.get('aws');
    this.dynamodbClient = DynamoDBDocumentClient.from(new DynamoDBClient(awsConfig));
  }
  async get(test: string): Promise<object | undefined> {
    const getQuery = new GetCommand({ TableName: this.TABLE_NAME, Key: { test } });
    return data.Item;
}
}
Service.ts
import Repo from '../repositories/Repo';
export default class t { 
constructor(
  private repo: Repo,
) {}
public async test(bodyRequest: any, headers: any): Promise<any> {
  const test: any = await this.repo.getByChecksum('123');
}
}

Observed Behavior

An error is produced when trying to acces the DB.

Expected Behavior

No error using config.

Possible Solution

Using DynamoDBDocumentClient.from(new DynamoDBClient(JSON.parse(JSON.stringify(config.get('aws')))) fix the issue.

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.closed-for-stalenessguidanceGeneral information and guidance, answers to FAQs, or recommended best practices/resources.p3This is a minor priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions