This is a project to manage approval requests using AWS serverless infrastructure.
- It's not possible to create multiple requests of the same type for the same origin.
 - You have to specify user sub manually in GraphQL queries and mutations.
 - No unit tests (yet).
 
- Make log level configurable.
 - Use another authentication type for API calls (instead of API KEY).
 - Be able to fetch user sub from API calls (from token or lambda context);
 - Use DynamoDB Streams to interact with consumer services in a more event driven way.
 
By default, [default] AWS profile is used for AWS CDK configuration.
If you want to use another named profile, you could specify it in cdk.json file as"profile": "your_profile_name"
or provide a --profile your_profile_name parameter to AWS CDK commands.
Make sure you have typescript and aws-cdk installed.
For the first time run cdk bootstrap command:
cdk bootstrapRun cdk synth to synthesize an AWS CloudFormation template:
cdk synthRun cdk deploy:
cdk deploySpecify a named profile parameter to AWS CDK commands if needed
cdk command --profile your_profile_nameTo send a custom event to the approval event bus you should specify correct values for the Event source and Event details fields.
The Detail type field is not used, so it could contain any valid value.
Event bus:
serverless-approvals-dev-source
Event details:
{
  "action": "create",
  "originType": "transaction",
  "originId": "QWERTY",
  "sub": "user-sub-1"
}You could fetch pending (not processed) approval requests by using getPendingRequests query.
Additionally, requests could be filtered by originType or originTyId.
query MyQuery {
  getPendingRequests(filter: {originType: "transaction"}) {
    action
    originId
    originType
    status
    createdBy
  }
}You could fetch pending (not processed) approval requests, which could be reviewed by current user (were not originally created by this user).
In this case you have to provide user sub as a filter parameter.
query MyQuery {
  getReviewableRequests(filter: {sub: "user-sub-2", originType: "transaction"}) {
    action
    originId
    originType
    status
    createdBy
  }
}You could approve or reject pending approval requests, which were originally created by other user.
mutation MyMutation {
  approveRequest(
    input: {
      action: "create"
      message: "Approved",
      originId: "QWERTY",
      originType: "transaction",
      sub: "user-sub-2"}) {
    action
    originId
    originType
    status
    updatedAt
  }
}
mutation MyMutation {
  rejectRequest(
    input: {
      action: "create"
      originId: "QWERTY",
      originType: "transaction",
      sub: "user-sub-2"}) {
    action
    originId
    originType
    status
    updatedAt
  }
}npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testscdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template
