I am facing an issue with calling the AWS AppConfig provide to get some feature flags, according to the docs, the token expires after up to 24hrs.
I think this should be handled by the lib internally and looking at its source code it does but the token is still invalid after some time, requiring manual service redeployment.
I am using the AWS SDK v3 with typescript, nestjs and lambda powertools
The code:
import { AppConfigProvider } from '@aws-lambda-powertools/parameters/appconfig';
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Config } from 'src/config/types/interfaces';
import { FeatureFlagList } from './types/interfaces';
constructor(private readonly configService: ConfigService<Config, true>) {
this.configProvider = new AppConfigProvider({
// clientConfig: { logger: this.logger },
application: this.configService.get('aws.appConfig.appName', {
infer: true,
}),
environment: this.configService.get('aws.appConfig.envName', {
infer: true,
}),
});
}
public async getConfig(): Promise<FeatureFlagList> {
let config: FeatureFlagList;
try {
config = (await this.configProvider.get(
this.configService.get('aws.appConfig.profileName', { infer: true }),
{ maxAge: APP_CONFIG_MAX_AGE_SECONDS, transform: 'json' },
)) as unknown as FeatureFlagList;
} catch (error) {
this.logger.error('featureFlagService.getConfig', { err: error });
config = {
chat: { enabled: false },
};
}
return config;
}
The error:
{"level":"error","time":1708267026762,"pid":1,"hostname":"f281cd3e9f1e","err":{"type":"GetParameterError","message":"Token not valid","stack":"GetParameterError: Token not valid\n at AppConfigProvider.get (/usr/src/app/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@aws-lambda-powertools/parameters/lib/base/BaseProvider.js:92:19)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n at async FeatureFlagService.getConfig (/usr/src/app/dist/src/api/configuration/feature-flag.service.js:38:23)\n at async ConfigurationController.getFeatureFlags (/usr/src/app/dist/src/api/configuration/configuration.controller.js:26:50)","name":"GetParameterError"},"msg":"featureFlagService.getConfig"}
The code works fine until it doesn't, automatic token refresh doesn't work. My container runs in EC2 instance so its not a Lambda per say, but I believe it shouldn't matter?