Skip to content

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

License

Notifications You must be signed in to change notification settings

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.

The list of MP accounts to be included by the scheduler, whether production or for testing purposes, is determined by the following criteria based on information obtained from the github/ministryofjustice/modernisation-platform/environments json files.

  • the account-type is "member"
  • the account is not production
  • the field "instance_scheduler_skip": ["true"] has NOT been added to the "environment" list in the json.

If the account does not meet any of the above criteria then it is excluded.

Requirements

Testing changes to the go source code of the module can be done by creating a Pull Request with a new branch containing the changes. The log output of the github workflow build-test-push.yml will show the results.

For development & running the scheduler locally:

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

Note that setting a local environment variable INSTANCE_SCHEDULING_SKIP_ACCOUNTS is no longer required and it is not used.

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