Deploying Static Website to S3 with AWS CodeBuild

There are a few AWS devops services, CodeDeploy, CodeBuild and CodePipeline. They have similar name and it’s confusing at first. CodeBuild is the service to create an artefact. In CodeBuild, we can install dependencies, run unit tests, create an artefact and push to the artefact repository. CodeDeploy uses the artefact and deploy the code to the environment. CodePipeline is the orchestrator.

When we want to deploy a static website or frontend widget to S3 and directly serves those static assets from there, CodeBuild itself can do all of it. In the build project, we specify the repo and use buildspec.yml to install dependencies, run tests, compile and push to S3. Then, those assets can be served from the bucket directly.

buildspec.yml defines the actions that happens in CodeBuild. Each phase, we can run Linux command. It also allows to pass the variables from the CodeBuild. It will read the buildspec file at the root of your repo.

Now, let’s see the example to push JavaScript widget to S3 bucket. Since the bucket uses CloudFront as CDN, we need to clear CloudFront cache after each deployment. It can be done with aws cli command.

The buildspec file only creates an artefact. In CodeBuild, we need to specify the Artifact upload location to the target S3 bucket.

That’s it. We don’t need to use CodeDeploy or CodePipeline to deploy frontend widget to S3 bucket. Pretty cool.

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …