Thanks to Lucas' mama

2021-09-06
AWS API Gateway notes

Basice Concepts

  • REST
    REpresentational State Transfer is a software architectural style.
  • RESTful
    A web API that obeys the REST constraints is informally described as RESTful:
    • A client-server architecture made up of clients, servers, and resources, with requests managed through HTTP
    • Access resources via URI and URL-encoded parameters
    • Use of JSON or XML to transmit data.
    • Stateless client-server communication
    • Cacheable
Wikipedia and Redhat
Read More

2021-08-30
AWS CI/CD for API gateway

In this post, I will share how to set up a continuous integration and continuous delivery (CI/CD) pipeline on AWS for API gateway. The following AWS services will be used:

  • Cloudformation allows you to model your entire infrastructure and application resources
  • CodePipeline is a continuous delivery service
  • CodeCommit is a version control service
  • CodeBuild is a fully managed build service in the cloud
  • Simple Storage Service (Amazon S3) is storage for the Internet
  • API Gateway is an AWS service for creating, publishing, maintaining, monitoring, and securing REST, HTTP, and WebSocket APIs
  • AWS Lambda is a serverless compute service
Read More

2021-08-17
Create AWS Lamdba Layer

Suppose I want to upload MaxMind GeoIp city database to AWS, and make it as Lambda layer.

Read More

2021-08-12
Useful software

Read More

2021-08-11
AEM - Get incoming links to a page

Ubuntu 16.04.4 LTS AEM 6.4

  • Use Python script to get the Reference of a page in AEM
    • Use your own AEM admin password HTTPBasicAuth('admin', 'password')
    • XPath to get all incomingLinks
    • Install lxml (please refer to Use Python to read HTML element by XPath)
      test.py
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      from lxml import html
      import requests

      # print (requestURL)
      page = requests.get("http://localhost:4502/mnt/overlay/wcm/core/content/sites/jcr:content/rails/references/items/references.provider.html?item=/content/mysite/intl/en/test", auth=requests.auth.HTTPBasicAuth('admin', 'password'))
      # print (page.content)
      content = html.fromstring(page.content)
      links = content.xpath('//section[@data-type="incomingLinks")]/@data-path')
      # Remove duplicate links
      links = list(set(links))

      for link in links:
      print (link)

  • Run the script
    1
    python3 test.py
Read More

2021-08-09
Use Python to read HTML element by XPath

Ubuntu 16.04.4 LTS

  • Use Python 3 to read an HTML element attribute: data-endpoint by XPath and lxml
Read More

2021-08-05
JavaScript Notes

  • Get all hyperlinks and remove line breaks
    var links = document.getElementsByTagName("a");
    for(var i=0; i<links.length; i++) {
    console.log(jQuery.trim(links[i].href) + "," + jQuery.trim(links[i].innerText).replace(/(?:\r\n|\r|\n)/g, ''));
    }
Read More

2021-07-22
AEM - setup cold standy author

On Standby

  1. Stop the synchronization process
  2. Stop AEM service
    sudo service aem stop`
  3. Check AEM java process is terminated
    $ ps -ef | grep java
    calviny  10755 10409  0 11:55 tty1     00:00:00 grep --color=auto java
  4. scp -pr /aem/author.primary aem-user@author2:/aem/author.standby
  5. Delete sling.id.file
    $ cd crx-quickstart/launchpad
    $ find . -name sling.id.file
    ./felix/bundle12/data/sling.id.file
    $ rm ./felix/bundle12/data/sling.id.file
    
  6. Update the run mode to standby in crx-quickstart/bin/start
    CQ_RUNMODE='author,nosamplecontent,prod,standby,aws'
  7. Start AEM service
    sudo service aem start`
Read More

2021-07-21
Node.js notes

Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.

npm

npm is the default package manager for the JavaScript runtime environment Node.js

1
2
3
4
5
6
7
8
9
# Install package
npm install package-name

# Check outdated packages
npm outpdated

# Run arbitrary package scripts in package.json
npm run

nodemon

  • nodemon will read the package.json for the main property
  • nodemon will also search for the scripts.start property in package.json

Documentation

exports / require

module.exports is used for defining what a module exports and makes available through require()
(1) The exports variable is available within a module’s file-level scope, and is assigned the value of
module.exports before the module is evaluated.

(2) However, be aware that like any variable, if a new value is assigned to exports, it is no longer bound to module.exports

Manage Node.js versions

n nvm
Overall Node module Bash script
Supported platforms macOS, Linux, including with Windows Subsystem for Linux. n does not work in native shells on Microsoft Windows unix, macOS, and windows WSL. For Windows, nvm-windows
Installation npm install -g n curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Installing Node.js Versions n nvm install node
# “node” is an alias for the latest version

npm install installs dependencies into the node_modules/ directory
npm run build does nothing unless you specify what “build” does in your package.json file

Read More

2021-07-20
Upgrade AWS Lambda Node.js version

AWS has announced the end of support for Node.js 10.x. Hence, I have to upgrade our existing Node.js 10.x Lambda functions to 14.x.

Read More