Sign in

Offical website, https://www.pulumi.com/

Installation

brew install pulumi

Sign up a new account in pulumi website since you need a Access Token

Then go to https://app.pulumi.com/socloud/settings/tokens, create new token

Back to terminal, login your pulumi account

pulumi login

You can see which account your logged in by using

pulumi whoami

Start new project, …

mkdir {your_new_project_folder}
cd {your_new_project_folder}
pulumi new

Below is a simple example for createing an s3 bucket

add modules/index.ts

Add dotenv package

yarn add dotenv

and place BUCKET_NAME key which is the name of the bucket name you want

BUCKET_NAME=cdn.example-1234.com

Add an index.ts in root

Run…


In terminal, generate ssh key

ssh-keygen -t rsa -C "your_username@your_email.com@bitbucket"

Will ask you file name to for generate this ssh key, and this example we are going to generate ssh for different git, e.g. bitbucket and github which using different ssh key

$ ssh-keygen -t rsa -C "your_username@your_email.com@github1"
$ ssh-keygen -t rsa -C "your_username@your_email.com@github2"

Next, setup your ssh config file, which located in your ~/.ssh folder

$ mkdir .ssh
$ cd .ssh
$ touch config

Here is an example of the config file

# GitHub michaelmaky
Host github-michaelmaky
HostName github.com
IdentityFile ~/.ssh/id_rsa_github_michaelmaky
# GitHub michaelmaky
Host github-michaelmaky2
HostName github.com …

Prerequisite

Install homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install java

brew install java
# if you want to install multi-version
brew install --cask adoptopenjdk8
brew install --cask adoptopenjdk11
brew install --cask adoptopenjdk16

these will be installed into /Library/Java/JavaVirtualMachines/ which is the traditional location on Mac OSX.

For M1 Mac, Since zsh is the default Terminal shell, so place script below either in your ~/zprofile / or ~/.zshenv or ~/.zshrc

export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_11_HOME=$(/usr/libexec/java_home -v11)
alias java8='export JAVA_HOME=$JAVA_8_HOME'
alias java11='export JAVA_HOME=$JAVA_11_HOME'
# default to Java 11
java11

then you can use command java8 or java11 to switch your java runtime…


To enable graphQL in your nestjs api, you can first read the offical document here.

Step 1, install npm package need

yarn add @nestjs/graphql graphql-tools graphql graphql-type-json apollo-server-express

declare a simple factory class for graphQL

In app.module.ts, add GraphQL module

and also define .gql under schema

Next, create order.resolver.ts which make graphQL support same request as restful, which define in order.controller.

Use postman to make a request for getOrders, we copy the sample request query and variable below

Here is the result which same as using restful API

The sample code is here, hope this help.


Go to Stripe to create an account

Navigate to left menu > Developers > API keys, there is a publishable key and secret key, publishable key is used in front end below checkout

Imagine there is an checkout form in web / app, you input credit card, CVC, expired month and year in the form and checkout, In stripe, you need to use those information to get the source id of this payment

Below we use postman with the publishable key to get source id

You can copy your publishable key to the environment variables of postman, and request body…


nest new nestjs-api

Install mongoose package and create mongo db connection helper, this helper can works fine with local mongodb and mongodb altas

Ref: https://docs.mongodb.com/manual/reference/connection-string/#connection-string-options

Import mongoose module into App module

Order Module

Generate our first module using generator, ref: https://docs.nestjs.com/recipes/crud-generator

nest g resource orders

As I need to works with mongodb, I need to rename folders


In this tutorial, I’ll build a simple NodeJS API which will be deployed in AWS Lambda and the endpoints will be exposed using AWS API gateway. The deployment will use Bitbucket pipelines which allow you to preform CICD when code change in a specific branch, also the configuration will be defined in AWS SAM template.

Cloudformation (SAM) allows you to manage your AWS infrastructure using just a yaml file. Using these two tools you can create a solid CD environment from scratch.

Suppose you have an AWS account and now create an IAM user with following policies

IAMFullAccess
AmazonS3FullAccess
AmazonAPIGatewayAdministrator
AWSCloudFormationFullAccess
AWSLambda_FullAccess…

Step 1: Setup for s3 website

Refer to here you can setup: https://docs.aws.amazon.com/AmazonS3/latest/userguide/WebsiteHosting.html

Step 2: Setup DNS, e.g. cloudfare

After setup CNAME of your website host in AWS S3, you can see your website content “Welcome to my website” base on document below

Step 3: Setup IAM user which can access this bucket

Refer to my other tutorial

Step 4: Setup Deployment variables of your repo

Refer to my other tutorial,

Define Deployment variables

AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
S3_BUCKET: $BUCKET_NAME

Step 5: update package.json script, we use max_old_space_size=2048 since the ci server is not a very powerful machine


Prepare a Security group for elastic cache

Search VPC and you will see below information

Add a new security group which same as this VPC


First Part is about AWS SES setup guileline

Go to AWS Console, enter SES Home

https://ap-southeast-1.console.aws.amazon.com/ses/home?region=ap-southeast-1#

Verify domain

Go to Domains > Verify a New Domain button, enter your domain, it shows picture below and you can use these information by input to your DNS management of this domain, e.g. cloudflare

Normally, within 24 hours or less, AWS SES will finish verify your domain and go back to SES console page, status update to verified

Kingyinma

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store