A serverless typescript project for the Account Intervention Service solution.
git clone git@github.com:govuk-one-login/account-interventions-service.git
cd account-interventions-service
pip install gitlint
pre-commit install -f
$ pre-commit install --hook-type commit-msg
$ yarn postinstall
$ yarn install
To fully test the application, try the test command below
$ yarn test
To build the application code and deploy the ais-main stack use the following commands from project root directory.
Make sure NOT to pass a --template / -t flag to the sam deploy
command. By simply running sam deploy --guided
SAM will pick up the relevant version of the main template from the default directory .aws-sam/build
which is created during the build process
Ensure you have logged into AWS and obtained credentials before attempting to deploy manually
$ yarn package
$ sam deploy --guided
To manually deploy the ais-alarm stack, use the following commands from project root directory. Ensure you have logged into AWS and obtained credentials before attempting to deploy manually.
$ sam deploy --guided -t src/infra/alarm/template.yaml
To manually deploy the ais-core stack, use the following commands from project root directory. Ensure you have logged into AWS and obtained credentials before attempting to deploy manually.
$ sam deploy --guided -t src/infra/core/template.yaml
$ yarn lint
yarn lint:code
- TypeScript is linted by ESLintyarn lint:iac
- SAM template is linted by SAM CLIyarn lint:spec:oas
- OpenAPI specification is linted by Spectral
$ yarn lint:code:fix
$ yarn audit
$ yarn audit:fix
To deploy the base common CloudFormation stacks required created by Dev Platform prior to deploying the solution use the Stack Orchestation tool provided in our stack-orchestration directory and run the production_bootstrap.sh script.
The stacks to be deployed are:
- alerting-integration
- api-gateway-logs
- certificate-expiry
- vpc
- lambda-audit-hook
- checkov-hook
- infra-audit-hook
$ aws configure sso
- Choose session name: {enter your name}
- Accept authorisation in browser
- Choose the AWS account in the dropdown
- CLI default client Region: eu-west-2
- CLI default output format: json
- aws sso login --profile _{profile name provided for account}
⚡ Prior to deploying check the latest versions of these stacks are being referenced which can be found here > CHANGELOG
$ cd stack-orchestation
$ aws configure sso
$ aws sso login --profile di-account-intervention-admin-324281879537
$ sh production_bootstrap.sh
The bootstrap script should deploy all base Cloudformation stacks required for account set up.
Clone the ais-infra repo
git clone git@github.com:govuk-one-login/ais-infra.git
cd ais-infra
$ pre-commit install -f
These pipelines should deploy the main solution stacks
ais-core-pipeline
deploy ourais-core
stackais-main-pipeline
deploys ourais-main
stackais-alarm-pipeline
deploys ourais-alarm
stack
Setup these 3 secure pipelines by using the Stack Orchestation tool provided in our Stack-Orchestration directory and run the production_pipelines.sh script.
⚡ Prior to deploying check the latest version of secure pipelines is being referenced in the production_pipelines.sh script > CHANGELOG
$ cd stack-orchestation
$ aws configure sso
$ aws sso login --profile di-account-intervention-admin-324281879537
$ sh production_pipelines.sh
Once all production pipelines have been set up, proceed to running the staging_pipelines.sh script to allow promotion up to production
account.
$ cd stack-orchestation
$ aws configure sso
$ aws sso login --profile di-id-reuse-core-staging-admin-922902741880
$ sh staging_pipelines.sh
❗ Update this table if version has been updated
ais-main-pipeline | ais-core-pipeline | ais-alarm-pipeline | alerting-integration | api-gateway-logs | certificate-expiry | vpc | ecr-image-scan-findings-logger | lambda-audit-hook | checkov-hook | infra-audit-hook | |
---|---|---|---|---|---|---|---|---|---|---|---|
Dev | v2.48.0 | v2.48.0 | v2.48.0 | v1.0.6 | v1.0.5 | v1.1.0 | v2.3.1 | v.1.1.4 | n/a | n/a | n/a |
Build | v2.48.0 | v2.48.0 | v2.48.0 | v1.0.6 | v1.0.5 | v1.1.0 | v2.3.1 | v.1.1.4 | n/a | n/a | n/a |
Staging | v2.48.0 | v2.48.0 | v2.48.0 | v1.0.6 | v1.0.5 | v1.1.0 | v2.3.1 | v.1.1.4 | n/a | n/a | n/a |
Integration | v2.48.0 | v2.48.0 | v2.48.0 | v1.0.6 | v1.0.5 | v1.1.0 | v2.3.1 | v.1.1.4 | n/a | n/a | n/a |
Production | v2.48.0 | v2.48.0 | v2.48.0 | v1.0.6 | v1.0.5 | v1.1.0 | v2.3.1 | n/a | n/a | n/a | n/a |
If you already have an earlier version of SAM installed you may need to either upgrade SAM or uninstall it and reinstall it. Here are some instructions you can follow to do this:
$ brew upgrade aws-sam-cli
Managing AWS SAM CLI versions - AWS Serverless Application Model
The command may be required if you do not already have pre-commit installed on your machine
$ brew install pre-commit
If you work across multiple Node.js projects there's a good chance they require different Node.js and npm versions.
To enable this we use nodenv to switch between versions automatically.
- Install and setup nodenv.
- Install the NodeJS version used by this project
nodenv install <node-version>
.
$ brew install nodenv
$ nodenv init
$ cat .node-version | nodenv install
Getting latest releases of Node Version supported by nodenv (this may take a while)
brew upgrade nodenv node-build
The api in this application is a private api, which means testing it can't be done using tools like postman. The lambda {stack-name}-InvokePrivateAPIGatewayFunction
has been created to allow the api to be tested. Since this lambda is created within the application's VPC, it meets the required security measures so it is able to successfully invoke the endpoint.
The api has the following format:
<baseurl>/ais/:userId?history=true
Note: the query string parameter (history=true
) is optional.
This lambda sets default values for the baseUrl and the endpoint (e.g. ais
) in the environment variables.
There are two ways to use this lambda:
All of these keys are optional. Anything provided in the event will override the default value in the environment variable.
{
"userId": "<theUserId>",
"queryParameters": "history=true",
"baseUrl": "<theBaseUrl eg http://hello-world.com>",
"endpoint": "<theEndpoint eg /ais>",
"headers": { 'Content-Type': 'application/json' } // add any headers here
}
Update the values for these variables. Note, if you also provide the equivalent value in the lambda event, the lambda will use the lambda event values.
USER_ID
QUERY_PARAMETERS
BASE_URL
END_POINT
Note: that at the moment the lambda is not set up to work for a post request, so changes to the lambda will need to be made if post requests become a requirement.