I could not get the database username and password passed to the config/config.js from .github/workflows/deploy.yml. When I pushed the codes to the GitHub. The GitHub Actions automate the deployment and ran the sequelize commands which turned out to be successful as it was getting all the secrets such as username, password, database name, and host. When I tried to have these confidential variables passed to config/config.js, the DB_NAME and DB_HOST are working but DB_USERNAME and DB_PASSWORD appeared to be undefined. I have found out about this issues when I was looking at the console log from the AWS CloudWatch because there was an error when the user is creating an account. Post confirmation basically checks the user and assign the role based on their email domain. This process requires an access to the Postgres database.
I have tried changing the variable name such as from “DB_USERNAME” to “USERNAME” and applied the same way for password, database name, and host. I have updated the variable name from deploy.yml and config/config.js. However, they all turned out to be undefined when I looked at the console logs from the CloudWatch. So, I have changed the variable names back. The username and password are undefined while the database and host show the values. I am not sure if this has to do with the naming or not.
.github/workflows/deploy.yml:
name: Deploy to AWS
on:
push:
branches:
- main
permissions:
id-token: write
contents: read
env:
AWS_REGION: 'us-east-1'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install dependencies
run: npm install
- name: Install AWS CDK
run: npm install -g aws-cdk
- name: Install ts-node
run: npm install -g ts-node
- name: List files for debugging
run: ls -R
- name: Verify cdk/bin contents
run: ls -R cdk/bin
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{secrets.ROLE_TO_ASSUME}}
aws-region: ${{env.AWS_REGION }}
role-session-name: GitHubActions
- name: Install frontend
working-directory: frontend/frontendapp
run: npm install
- name: Build frontend
working-directory: frontend/frontendapp
run: npm run build
- name: CDK deploy
run: cdk deploy --all --require-approval never --app "npx ts-node cdk/bin/cdk_test.ts"
- name: Run Sequelize commands
env:
DB_USERNAME: ${{secrets.USERNAME}}
DB_PASSWORD: ${{secrets.PASSWORD}}
DB_NAME: ${{secrets.DATABASE}}
DB_HOST: ${{secrets.HOST}}
run: npx sequelize db:migrate --config config/config.js
config/config.js:
console.log("Database Config from config/config.js:");
console.log("Development Username:", process.env.DB_USERNAME);
console.log("Development Password:", process.env.DB_PASSWORD);
console.log("Development Database:", process.env.DB_NAME);
console.log("Development Host:", process.env.DB_HOST);
module.exports = {
development: {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'postgres'
},
test: {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'postgres'
},
production: {
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: process.env.DB_HOST,
dialect: 'postgres'
}
};
Thank you in advance.
Awais Nisar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.