Continuous Improvement for Software Engineers

Instructions, notes and guides to help with continuous software improvement.

View on GitHub

AWS Cloud DevOps Instructions

The following scripts create a code repository folder that followed devops principles to create the cloud infrastructure need to deploy a software application.

You can choose between webpack (popular and complicated) or esbuild (new and very faster) for packaging typescript cloud objects.

Software testing should use Gherkin syntax to encourage Behaviour-Driven Development (BDD) and enable reporting of test results in a human readable format.

Prerequisite Software

Windows 11 Prerequisite installation


winget install -e --id Microsoft.PowerShell
winget install -e --id Microsoft.VisualStudioCode
winget install -e --id OpenJS.NodeJS.LTS
winget install -e --id Amazon.AWSCLI
winget install -e --id Amazon.SAM-CLI
winget install -e --id Docker.DockerDesktop

Create a Code Repository

The following script enables you setup many code repositories and installs tools that will be required to repeat this many times.

Npm instructions

# Npm configuration
npm --version
npm install -g aws-cdk esbuild cypress gitignore jest lerna typescript webpack webpack-cli yarn 
npm config ls -l
npm config set init-author-name "{The org you work for}" -g 
npm config set init-author-email "suppor@{yourOrg}.io" -g 
npm config set init-author-url "https://dev.azure.com/{org}/{project}/_git/" -g 
# https://opensource.org/license/rpl-1-5/
npm config set init-license "RPL-1.5" -g 

Yarn instructions

# Yarn Configuration
yarn --version
yarn global add aws-cdk cypress esbuild gitignore jest lerna readme-md-generator typescript webpack webpack-cli
yarn config list
yarn config set init-author-name "{The org you work for}" -g 
yarn config set init-author-email "suppor@{yourOrg}.io" -g
yarn config set init-author-url ""https://dev.azure.com/{org}/{project}/_git/" -g
# https://opensource.org/license/rpl-1-5/
yarn config set init-license "RPL-1.5" -g

Create Software Code Repository

The following script creates a standard code repository folder structure that should help make all code repositories consistently structured.

# TODO: Change your default code repository location
cd ~\source\repos\
ls
md vip-software-flavour
cd vip-software-flavour

# Create repository folders
md docs,infrastructure\cdk,infrastructure\terraform,pipeline,src\functions,src\website,src\endpoint,src\api

# Create standard repository files.
yarn init -p
yarn add -D gitignore readme-md-generator lerna 
npx lerna init --packages="infrastructure/cdk/*" --packages="src/*" --independent
npx gitignore VisualStudio
npx readme-md-generator
"" > LICENSE.md
"" > init.ps1

Configure Package Repositories and Cloud accounts and Git Remote repositories

TODO: Add instructions for Artifact repositories and cloud vendors here.

 git init
 git commit
 #git remote add origin https://github.com/{Org}/{repo}.git
 #git remote add origin https://dev.azure.com/{Org}/{Project}/_git/{repo}
 git pull
 git push

Create an AWS CDK deployment stack

Creates a simple AWS CDK infrastructure stack that creates a cloud formation stack that can be deployed to your AWS Account directly or indirectly.

For local development & debugging you can choose AWS SAM CLI or the Serverless framework CLI

Uses Jest type script tests to confirm your infrastructure as code works as expected. Ideally we would be testing with BDD style in cypress.io

AWS CDK Yarn instructions

cd infrastructure\cdk
cdk init app --language typescript
yarn init -p
yarn add -D @types/jest @types/node jest jest-junit ts-jest ts-node typescript
sam init --app-template hello-world-typescript --name sam-app --package-type Zip --runtime nodejs18.x

Create a Typescript AWS Lambda function

Creates a lambda function function with typescript and nodejs, and sets up cypress BDD tests. It uses powertools for AWS Lambda typescript. Uses ESBuild rather than Webpack. Parts of this can be done in Visual Code via the AWS Toolkit plugin

# Add Aws Lambda typescript
cd .\src\functions\
md get-hello-world-text
cd get-hello-world-text
tsc -v
# ES2018 support inferred from AWS Github lambda examples. 
# https://github.com/aws-samples/serverless-typescript-demo/blob/main/tsconfig.json
tsc --init --target ES2018 --strictPropertyInitialization false
yarn init -p
yarn add -D @aws-lambda-powertools/logger  @aws-lambda-powertools/metrics @aws-lambda-powertools/tracer @aws-sdk/client-lambda @types/aws-lambda @types/node aws-cdk esbuild
# Use AWS Sam to create 
sam init --app-template hello-world-typescript --name sam-app --package-type Zip --runtime nodejs18.x
cd sam-app
sam build

# Start Docker desktop, for Aws SAM CLI
docker -v
docker container ls

# AWS CLI authenticate.

# Run Lambda once with a set event
sam local invoke HelloWorldFunction --event events/event.json

# Run Lambda behind API Gateway 
sam local start-api
#sam local start-api --debug-port 5858

# Run Lambda by iteself
sam local start-lambda
#sam local start-lambda --debug-port 5858
#Ctrl+C to stop the local service.

# Test the Lambda locally and send the response to a json file.
cd ~\
aws lambda invoke --function-name HelloWorldFunction --endpoint "http://127.0.0.1:3001" AppData/Local/Temp/lambda-response.json
code ~/AppData/Local/Temp/lambda-response.json

References