powertools-lambda-typescript
powertools-lambda-typescript copied to clipboard
Bug: AWS AppConfigProvider error, unable to retrieve feature flags after some time
Expected Behaviour
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.
Current Behaviour
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. This requires me to restart the service each time it expires which is not ideal. I m running this in an EC2 container utilising the Nestjs framework
Code snippet
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';
export const APP_CONFIG_MAX_AGE_SECONDS = 60 * 5; // 5 minutes
@Injectable()
export class FeatureFlagService {
private readonly configProvider: AppConfigProvider;
private readonly logger = new Logger(FeatureFlagService.name);
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;
}
}
Steps to Reproduce
- Build base image with node:19.0.1
- Run with node:19.0.1-alpine
- Let it serve on EC2 task
- After (not sure if exactly) 24 hours we get the token error
Possible Solution
No response
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
Stacktrace error
{"level":"error","time":1708266970318,"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"}
Thanks for opening your first issue here! We'll come back to you as soon as we can. In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link
Hi, thank you for opening this issue.
Could you please confirm which version of Powertools are you using? In the issue you've selected latest
but the execution log you have shared below seems to show you're using version 1.17.0
.
In version 1.18.0 we have released a fix for this issue, so before trying to reproduce on our side I'd like to confirm your version.
If possible, could you please try to upgrade to version 1.18.0 or newer and check if you're still observing this behavior?
This issue has not received a response in 2 weeks. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.
Greetings! We are closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or reopen the issue.