isomerpages / isomercms-backend

A static website builder and host for the Singapore Government
5 stars 1 forks source link

Is 185 backend add in integrations with site launch and step functions #775

Closed kishore03109 closed 1 year ago

kishore03109 commented 1 year ago

Problem

This PR was an attempt to make the serverless functions use ddb instead. However, the difficulties encountered were greater than the effort to just migrate everything over to Pulumi, and thus PR is now abandoned. I am still leaving the commits here to serve as a reference in the future on why just using serverless did not work as well as expected. 😢

Solution

Technical Decisions made

Existence of 2 state machines definitions

Due to the removal of queues, there is a change in the shape of the message as queues modify the message slightly. This leads to different shapes for the inputs, specifically, InputPath: $.Records[0].body for the queues, and InputPath: $.body for just using the dynamo db. Ideally, we could have done something like InputPath: ${Boolean(env:USE_BODY_PATH) ? '$.body' : '$.Records[0].body'} to have some sort of control flow based on the env var at deploy time. However, serverless doesnt do too well custom if conditions like this .

As a hacky workaround, this PR introduces two separate definitions, and have a separate flag in the command line to decide which version infra to deploy. However, the above attempt also didnt work due to limitation described here. Recontinuing the effort to move to use pulumi, else this going to end up making quite a bit of changes to our stepfunctions lambda code to make this to work

Tests

To mimic an actual site launch process, one can implement write this in server.js:

const message = {
  repoName: "kishore-test",
  appId: "d2o1jqfefd52uh",
  primaryDomainSource: "kishorewithwww.isomer.gov.sg",
  primaryDomainTarget: "d3p2fij9tvbt0v.cloudfront.net",
  domainValidationSource:
    "_0710dc63378cf3eb51c76fc55edbb51b.kishorewithwww.isomer.gov.sg",
  domainValidationTarget:
    "_4046887c88cf94a6e7b651c8a04abe70.yygwskclfy.acm-validations.aws",
  requestorEmail: "kishore@open.gov.sg",
  agencyEmail: "alexander@open.gov.sg",
  redirectionDomain: [
    {
      source: "kishorewithwww.isomer.gov.sg",
      target: "18.136.36.203",
      type: "A",
    },
  ],
}
dynamoDBService
  .createItem(message)
  .then((data) => {
    logger.info(`Successfully created item in DynamoDB: ${data}`)
    return data
  })
  .catch((err) => {
    logger.error(`Error creating item in DynamoDB: ${err}`)
  })

stepFunctionsService
  .triggerFlow(message)
  .then((data) => {
    logger.info(`Successfully triggered flow: ${data}`)
    return data
  })
  .catch((err) => {
    logger.error(`Error triggering flow: ${err}`)
  })
mergify[bot] commented 1 year ago

:warning: The sha of the head commit of this PR conflicts with #770. Mergify cannot evaluate rules on this PR. :warning: