i'm using serverless framework(aws).
From cloudFormation when creating a database, writes to the env. variable endpoint of the database.
part of my serverless.yml file
environment:
DATABASE_HOST:
"Fn::GetAtt": [ServerlessRDS, Endpoint.Address]
This variable is available from the lambda level as it is already deployed on aws. But I want to have access to this variable from locally. I came across the idea that I would write this variable to the parameter store (aws systems manager).
So I attached the script to my serverless.yml file (using serverless-scriptable-plugin).
scriptHooks, part of my serverless.yml file :
after:aws:deploy:finalize:cleanup:
- scripts/update-dbEndopint.js
Here's the script. Nothing special, writes an environment variable process.env.DATABASE_HOST to parameter stora.
const aws = require('aws-sdk');
const ssm = new aws.SSM();
(async () => {
try {
const params = {
Name: `${process.env.AWS_SERVICE_NAME}-DATABASE_HOST-${
process.env.AWS_STAGE
}`,
Value: `${process.env.DATABASE_HOST}`,
Type: 'String',
Overwrite: true,
};
await ssm.putParameter(params).promise();
log(`[DATABASE_HOST]: ${process.env.DATABASE_HOST} `);
log('Task done.');
} catch (e) {
throw e;
}
})();
But after taking deploy the variable is undefined. This is because the variable value is only available later.
Do you know how to get me to get the base endpoint to parameter store?