Skip to content

ministryofjustice/modernisation-platform-instance-scheduler

Repository files navigation

Ministry of Justice Instance Scheduler

Standards Icon Format Code Icon Scorecards Icon SCA Icon Build test push Icon

A Go lambda function for stopping and starting instance, rds resources and autoscaling groups. The function is used by the Ministry of Justice Modernisation Platform and can be re-used in any environment with minimal changes.

Requirements

To install the SAM CLI on macOS:

brew tap aws/tap
brew install aws-sam-cli

Local development

Install dependencies & build the target

cd modernisation-platform-instance-scheduler
make

⚠️ Code changes require a rebuild before you're able to run them. Use local-re-run.sh as a utility script when re-running local code changes.

Validate SAM template

aws-vault exec core-shared-services-production -- sam validate

Invoke Function

aws-vault exec core-shared-services-production -- sam local invoke --event event.json

Test Function in the Cloud

aws-vault exec core-shared-services-production -- sam sync --stack-name instance-scheduler --watch

Deploy on sprinkler-development using the local samconfig.toml and preventing prompts and failure when the stack is unchanged. The following command requires the instance-scheduler-ecr-repo ECR repository to be present in order to succeed.

ACCOUNT_ID=$(aws-vault exec sprinkler-development -- aws sts get-caller-identity --query Account --output text)
aws-vault exec sprinkler-development -- sam deploy --no-confirm-changeset --no-fail-on-empty-changeset --region eu-west-2 --image-repository $ACCOUNT_ID.dkr.ecr.eu-west-2.amazonaws.com/instance-scheduler-ecr-repo

Module initialisation. The following commands were used in order to generate the required go.mod and go.sum files prior to the first run of the tests.

cd instance-scheduler
go mod init github.com/ministryofjustice/modernisation-platform-instance-scheduler
go mod tidy
go mod download

Run Tests

cd instance-scheduler
aws-vault exec core-shared-services-production -- go test -v .

Configuration

  • Environment variable INSTANCE_SCHEDULING_SKIP_ACCOUNTS: A comma-separated list of account names to be skipped from instance scheduling. For example: export INSTANCE_SCHEDULING_SKIP_ACCOUNTS="xhibit-portal-development,another-development,". As can be observed in this example, every account name must be suffixed with a leading comma, hence the last comma in the list.

References

  1. User Guide
  2. How the original Go SAM project was created
  3. AWS Serverless Application Model
  4. AWS Serverless Application Repository
  5. Terraform module for deployment of the lambda

About

A Go lambda function for stopping and starting instance, rds resources and autoscaling groups • This repository is defined and managed in Terraform

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages