Challenges Solved during my Udacity Cloud developer course

Issue With Creating Postgres DB:

The problem was that the instructor created a free tier PostgreSQL db, but it seemed AWS no longer had a free tier for PostgreSQL db because i couldn't see the options for free tier, so i had to create a paid one for development with 15$ per month cost. I Later learned after some time that the PostgreSQL version selected by default had no free-tier, but selecting earlier versions showed the free tier option.

Issue with connecting to AWS RDS:

The problem was, I had to connect to the PostgreSQL db I had created on AWS, via the Postbird tool, which is a db management tool for PostgreSQL (like workbench for mysql) but was getting connection timed out response. The fix I applied was that I had to create a security group rule on the RDS instance to allow inbound traffic from anywhere. Basically setting inbound traffic to 0.0.0.0/0. And I was able to connect.

Issue with Sequelize:

The problem was that after cloning the project repo, which was an "ionic-typescript-PostgreSQL" stack, i had to start up the server and make calls to the endpoints. But, the server kept exiting without any errors. After investigations, I found out that I had to install a package known as 'pg'. So doing npm install pg@latest the issue was solved. The package 'pg' is a PostgreSQL client for Node.js.

Issue with AWS SDK:

The problem was that i needed to generate a signed URL for image upload to AWS S3. But the signed URL was returning the default AWS S3 link (s3.amazon.com) instead of something like,

"https://titanium-910393992277-bucket.s3.amazonaws.com/small-tree.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAH7I%2F20211010%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20211010T120117Z&X-Amz-Expires=300&X-Amz-Signature=9b89d1dd7707fd47afd927974ff98baa6dcfcdf91a11355&X-Amz-SignedHeaders=host

I later discovered that the issue was that the AWS credentials on my local computer was not correct and I had to setup a new IAM user for terminal access and change the local credential to that of the new IAM user.

Issue with health of instances after deployment with Elastic Beanstalk:

The problem was that after deployment, the health check of my instances were severe (red). To fix it, I inspected the logs via my terminal with the command eb logs. This showed my exactly what the problem was. In my case I was using Typescript for development and after zipping the build and uploading it to Elastic Beanstalk, the entry point for the app was pointing to server.ts which was no longer present in the build folder, because Typescript will compile down to Javascript. Hence server.ts becomes server.js. Changing the entry point to server.js fixed the issue.

Express server running but Localhost Refused to connect

Express server was running on port 8100 but could not connect on the browser. I changed to a different port 8080 on the app. And it worked. Later found out some other process was making use of the port 8100 at that time. Why didn't Express tell me that? I have no idea.

Micro-Services stuck on CrashLoopBackOff

I experienced issues after i deployed my micro-services with kubernetes via kubectl tool on terminal. The services got stuck on a CrashLoopBackOff. After hours of debugging, I checked the logs with kubectl logs command and found out that services were not getting the required values from the envs. Then, I later figured out that the envs weren't correctly set from the deployment.yaml file. So to fix it. I created a secret yaml file and configured the envFrom attribute to point to the env-secret file i had created. And all the crashing services started to run fine. Read about Kubernetes Secrets here => https://kubernetes.io/docs/concepts/configuration/secret/

Micro-Services crashing on server after pushing a new docker image

I built a new docker image on an M1 Mac without specifiying the platform, the microservice kept crashing because the build made use of the default OS platform with was arm64, and that could not run on the server. The fix applied was to specify a platform in the docker-compose which set to linux/amd64.

InvalidARN: ARN accountID does not match regex

I had this issue while trying to upload images to the s3 bucket. The cause was that the bucket name i specific in my environment variable looks like arn:aws:s3:::my-special-bucket. To fix it I changed it to my-special-bucket and the error was gone.

Upload to s3 not showing up / signed URL unavailable

I encountered this issue while trying to upload images to s3 via the signed URL. The issue was that the region I had set in my environment variable was us-east-1c which was incorrect, I fixed it by changing it to us-east-1 without the 'c'.

Lambda Function Showing 502 Bad Gateway

I encountered this error after deploying my lambda function with the Serverless framework. This was actually happening because my lambda function was throwing a validation exception, I saw that this was the case by checking the Cloudwatch logs for the function. Fixing the issues in the validation exception resolved it. Below is an example of one of the validation exceptions I got.

One or more parameter values were invalid: Type mismatch for key timestamp expected: S actual: N.

This meant the parameter timestamp was expected to be a string but I was sending a number.

Property 'Body' does not exist on type 'Request'

I encountered this error after writing a function to get images that have been uploaded to s3 using the typescript SDK. So my function looked like this.

const response = await s3
  .getObject({
    Bucket: bucketName,
    Key: key
  })
  .promise()

const body: Buffer = response.Body

After digging a bit deeper into the SDK code, I saw that could get the response body I needed by passing a second parameter into the getObject function as done below.

let body = null
await s3.getObject({
        Bucket: imagesBucketName,
        Key: key
    }, (err, data) => {
        if(err) console.log(err)
        body = data.Body
    })

The request signature we calculated does not match the signature you provided. Check your key and signing method

I go this error while trying to upload an image via a signed URL that was generated with AWS S3 SDK. After Some debugging, I solved it by changing the request method from GET to PUT.

Object notation for "service" property is not supported. Set "service" property directly with service name.

I got this error after running serverless deploy which is supposed to deploy my lambda function to AWS. I later discovered that the starter code I was using was written in an earlier version of the serverless framework. The simple fix was to update the serverless.yml file, from this:

//serverless.yml

service:
  name: serverless-app
....

to this:

//serverless.yml

service: serverless-app

And it worked fine.

Some were probably rookie mistakes but worth documenting.

I hope I save someone hours of debugging!

Have a nice day :)