Skip to content

Commit

Permalink
Update to version v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike O'Brien committed Apr 26, 2021
1 parent cc31291 commit d9208dd
Show file tree
Hide file tree
Showing 60 changed files with 819 additions and 355 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.4.0] - 2021-04-26
### Added
- Enable solution to be deployed as mutliple stacks in the same account/region
### Fixed
- Fix the SSM Maintenance window issue where solution was not fetching SSM Maintenance windows from other account/regions
- Updated logging utility to remove incorrect timestamp
- Fixed issue with scheduler stopping instances at UTC time even when configured with other timezones and Period having weekday configured as Wed#4. [Github Issue](https://github.com/awslabs/aws-instance-scheduler/issues/238)
- Modified Anonymous Data reporting refer implementation guide for details.
- Removed redundant logging of UTC timestamp along with the Account/Region default stamp in logs in AWS CloudWatch.
- Fixed [Github Issue](https://github.com/awslabs/aws-instance-scheduler/issues/184) for scheduler-cli.

## [1.3.3] - 2020-08-31
### Fixed
- Update the project to utilize aws cdk constructs for cloudformation template creation.
- Fix the issue for ensuring throttling is avoided to cloudwatch API's from github PR [#177](https://github.com/awslabs/aws-instance-scheduler/pull/177)
## [1.3.2] - 2020-06-22
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,28 @@ wget https://github.com/awslabs/aws-instance-scheduler/archive/master.zip

```
|- deployment/ - contains build scripts, deployment templates, and dist folders for staging assets.
|- cdk-solution-helper/ - helper function for converting CDK output to a format compatible with the AWS Solutions pipelines.
|- build-open-source-dist.sh - builds the open source package with cleaned assets and builds a .zip file in the /open-source folder for distribution to GitHub
|- build-s3-dist.sh - builds the solution and copies artifacts to the appropriate /global-s3-assets or /regional-s3-assets folders.
|- run-unit-tests.sh - runs the unit tests for the lambda files.
|- source/ - all source code, scripts, tests, etc.
|- bin/
|- aws-instance-scheduler.ts - the AWS Instance scheduler cdk app.
|- cli/ - scheduler-cli source files.
|- lambda/ - Lambda function with source code and test cases.
|- lib/
|- aws-instance-scheduler-stack.ts - the main CDK stack for aws instance scheduler solution.
|- aws-instance-scheduler-remote-stack.ts - the main CDK stack for aws instance scheduler solution remote template.
|- test/
|- __snapshots__/
|- aws-instance-scheduler-remote-stack.test.ts - unit and snapshot tests for aws instance scheduler.
|- aws-instance-scheduler-remote-stack.test.ts - unit and snapshot tests for aws instance scheduler remote stack.
|- aws-instance-scheduler-stack.test.ts - unit and snapshot tests for aws instance scheduler.
|- cdk.json - config file for CDK.
|- jest.config.js - config file for unit tests.
|- package.json - package file for the aws instance scheduler CDK project.
|- README.md - doc file for the CDK project.
|- run-all-tests.sh - runs all tests within the /source folder. Referenced in the buildspec and build scripts.
|- tsconfig.json - typescript configurations.
|- .gitignore
|- .viperlightignore - Viperlight scan ignore configuration (accepts file, path, or line item).
|- .viperlightrc - Viperlight scan configuration.
|- buildspec.yml - main build specification for CodeBuild to perform builds and execute unit tests.
|- CHANGELOG.md - required for every solution to include changes based on version to auto-build release notes.
|- CODE_OF_CONDUCT.md - standardized open source file for all solutions.
|- CONTRIBUTING.md - standardized open source file for all solutions.
Expand All @@ -81,7 +79,7 @@ AWS Solutions use two buckets: a bucket for global access to templates, which is

**Build the solution**

From the *deployment* folder in your cloned repo, run build-s3-dist.sh, passing the root name of your bucket (ex. mybucket), name of the solution i.e. aws-instance-scheduler and the version you are building (ex. v1.3.3). We recommend using a similar version based on the version downloaded from GitHub (ex. GitHub: v1.3.3, your build: v1.3.3.mybuild)
From the *deployment* folder in your cloned repo, run build-s3-dist.sh, passing the root name of your bucket (ex. mybucket), name of the solution i.e. aws-instance-scheduler and the version you are building (ex. v1.4.0). We recommend using a similar version based on the version downloaded from GitHub (ex. GitHub: v1.4.0, your build: v1.4.0.mybuild)

```
chmod +x build-s3-dist.sh
Expand All @@ -102,18 +100,18 @@ Confirm that all unit tests pass.

Upload the template and the lambda to your bucket in the following pattern,
```
s3://mybucket-us-east-1/aws-instance-scheduler/v1.3.3/instance-scheduler.zip (lambda Code)
s3://mybucket-us-east-1/aws-instance-scheduler/v1.4.0/instance-scheduler.zip (lambda Code)
```

Templates
```
s3://mybucket/aws-instance-scheduler/v1.3.3/instance-scheduler.template
s3://mybucket/aws-instance-scheduler/v1.3.3/instance-scheduler-remote.template
s3://mybucket/aws-instance-scheduler/v1.4.0/instance-scheduler.template
s3://mybucket/aws-instance-scheduler/v1.4.0/instance-scheduler-remote.template
```

## Deploy

See the [AWS Instance Scheduler Implementation Guide](https://s3.amazonaws.com/solutions-reference/aws-instance-scheduler/latest/instance-scheduler.pdf) for deployment instructions, using the link to the instance-scheduler.template from your bucket, rather than the one for AWS Solutions. Ex. https://mybucket.s3.amazonaws.com/aws-instance-scheduler/v1.3.3.mybuild/instance-scheduler.template
See the [AWS Instance Scheduler Implementation Guide](https://s3.amazonaws.com/solutions-reference/aws-instance-scheduler/latest/instance-scheduler.pdf) for deployment instructions, using the link to the instance-scheduler.template from your bucket, rather than the one for AWS Solutions. Ex. https://mybucket.s3.amazonaws.com/aws-instance-scheduler/v1.4.0.mybuild/instance-scheduler.template

## CDK Documentation

Expand All @@ -122,7 +120,7 @@ AWS Instance Scheduler templates are generated using AWS CDK, for further inform

***

Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at

Expand Down
1 change: 1 addition & 0 deletions deployment/build-open-source-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ source_dir="$source_template_dir/../source"
github_dir="$source_template_dir/../.github"
dist_template_dir="$dist_dir/deployment"


echo "------------------------------------------------------------------------------"
echo "[Init] Remove any old dist files from previous runs"
echo "------------------------------------------------------------------------------"
Expand Down
66 changes: 31 additions & 35 deletions deployment/build-s3-dist.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
#!/bin/bash
#
# This script packages your project into a solution distributable that can be
# used as an input to the solution builder validation pipeline.
#
# This script will perform the following tasks:
# 1. Remove any old dist files from previous runs.
# 2. Install dependencies for the cdk-solution-helper; responsible for
# converting standard 'cdk synth' output into solution assets.
# 3. Build and synthesize your CDK project.
# 4. Run the cdk-solution-helper on template outputs and organize
# those outputs into the /global-s3-assets folder.
# 5. Organize source code artifacts into the /regional-s3-assets folder.
# 6. Remove any temporary files used for staging.
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
# with the License. A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
# and limitations under the License.
#
# Parameters:
# - source-bucket-base-name: Name for the S3 bucket location where the template will source the Lambda
# code from. The template will append '-[region_name]' to this bucket name.
# For example: ./build-s3-dist.sh solutions v1.0.0
# The template will then expect the source code to be located in the solutions-[region_name] bucket
# - solution-name: name of the solution for consistency
# - version-code: version of the package

# Important: CDK global version number
cdk_version=1.53.0
cdk_version=1.96.0

# Check to see if the required parameters have been provided:
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
Expand All @@ -44,6 +35,10 @@ template_dist_dir="$template_dir/global-s3-assets"
build_dist_dir="$template_dir/regional-s3-assets"
source_dir="$template_dir/../source"


[ "$DEBUG" == 'true' ] && set -x
set -e

echo "------------------------------------------------------------------------------"
echo "[Init] Remove any old dist files from previous runs"
echo "------------------------------------------------------------------------------"
Expand All @@ -68,8 +63,8 @@ echo "--------------------------------------------------------------------------
# Install the global aws-cdk package
echo "cd $source_dir"
cd $source_dir
echo "npm install -g aws-cdk@$cdk_version"
npm install -g aws-cdk@$cdk_version
echo "npm install aws-cdk@$cdk_version"
npm install aws-cdk@$cdk_version

echo "------------------------------------------------------------------------------"
echo "NPM Install in the source folder"
Expand All @@ -79,18 +74,11 @@ echo "--------------------------------------------------------------------------
echo "npm install"
npm install

# Run npm run build && npm run test for the cdk component unit tests
echo "npm run build && npm run test"
npm run build && npm run test

# Run all the python tests.
echo "$template_dir/run-unit-tests.sh"
$template_dir/run-unit-tests.sh


# Run 'cdk synth' to generate raw solution outputs
echo "cdk synth --output=$staging_dist_dir"
cdk synth --output=$staging_dist_dir
echo "cd "$source_dir""
cd "$source_dir"
echo "node_modules/aws-cdk/bin/cdk synth --output=$staging_dist_dir"
npm run build && node_modules/aws-cdk/bin/cdk synth --output=$staging_dist_dir --no-version-reporting

# Remove unnecessary output files
echo "cd $staging_dist_dir"
Expand Down Expand Up @@ -128,7 +116,7 @@ mv version.py version.py.org
sed "s/%version%/$DIST_VERSION/g" version.py.org > version.py

echo "Install all the python dependencies in the staging directory before packaging"
pip install -r $source_dir/lambda/requirements.txt -t $staging_dist_dir/lambda/
pip install -U -r $source_dir/lambda/requirements.txt -t $staging_dist_dir/lambda/

echo "Build lambda distribution packaging"
zip -q --recurse-paths ./instance-scheduler.zip version.txt main.py version.py configuration/* requesthandlers/* chardet/* urllib3/* idna/* requests/* schedulers/* util/* boto_retry/* models/* pytz/* certifi/*
Expand All @@ -139,7 +127,15 @@ echo "cd into the scheduler cli folder ./cli"

cd ../cli
echo "Build the scheduler cli package"
zip -q --recurse-paths ./scheduler-cli.zip scheduler-cli/* setup.py instance-scheduler-cli-runner.py
mv ./setup.py ./setup.bak.py
echo "update the version in setup.py"
sed "s/#version#/$DIST_VERSION/g" ./setup.bak.py > ./setup.py
rm setup.bak.py
echo "update the version in scheduler_cli.py"
mv ./scheduler_cli/scheduler_cli.py ./scheduler_cli/scheduler_cli.bak.py
sed "s/#version#/$DIST_VERSION/g" ./scheduler_cli/scheduler_cli.bak.py > ./scheduler_cli/scheduler_cli.py
rm ./scheduler_cli/scheduler_cli.bak.py
zip -q --recurse-paths ./scheduler-cli.zip scheduler_cli/* setup.py instance-scheduler-cli-runner.py

echo "Copy the scheduler cli package to $build_dist_dir"
cp -pr ./scheduler-cli.zip $build_dist_dir/
17 changes: 8 additions & 9 deletions source/bin/aws-instance-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@ import { AwsInstanceSchedulerStack } from '../lib/aws-instance-scheduler-stack';
import { AwsInstanceSchedulerRemoteStack } from '../lib/aws-instance-scheduler-remote-stack';

const SOLUTION_VERSION = process.env['DIST_VERSION'] || '%%VERSION%%';
const SOLUTION_NAME = process.env['SOLUTION_NAME'];
const SOLUTION_ID = process.env['SOLUTION_ID'];
const SOLUTION_BUCKET = process.env['DIST_OUTPUT_BUCKET'];
const SOLUTION_TMN = process.env['SOLUTION_TRADEMARKEDNAME'];
const SOLUTION_NAME = process.env['SOLUTION_NAME'] ? process.env['SOLUTION_NAME'] : "aws-instance-scheduler";
const SOLUTION_ID = process.env['SOLUTION_ID'] ? process.env['SOLUTION_ID'] : "SO0030";
const SOLUTION_BUCKET = process.env['DIST_OUTPUT_BUCKET'] ? process.env['DIST_OUTPUT_BUCKET'] : "";
const SOLUTION_TMN = process.env['SOLUTION_TRADEMARKEDNAME'] ? process.env['SOLUTION_TRADEMARKEDNAME'] : "aws-instance-scheduler";
const SOLUTION_PROVIDER = 'AWS Solution Development';

const app = new cdk.App();


new AwsInstanceSchedulerStack(app, 'instance-scheduler', {
description: '(' + SOLUTION_ID + ') - ' + SOLUTION_NAME + ', version ' + SOLUTION_VERSION,
new AwsInstanceSchedulerStack(app, 'aws-instance-scheduler', {
description: `(${SOLUTION_ID}) - The AWS CloudFormation template for deployment of the ${SOLUTION_NAME}, version: ${SOLUTION_VERSION}`,
solutionId: SOLUTION_ID,
solutionTradeMarkName: SOLUTION_TMN,
solutionProvider: SOLUTION_PROVIDER,
solutionBucket: SOLUTION_BUCKET,
solutionName: SOLUTION_NAME,
solutionVersion: SOLUTION_VERSION
});
new AwsInstanceSchedulerRemoteStack(app, 'instance-scheduler-remote', {
description: '(' + SOLUTION_ID + ') - ' + SOLUTION_NAME + ' cross account role, version ' + SOLUTION_VERSION,
new AwsInstanceSchedulerRemoteStack(app, 'aws-instance-scheduler-remote', {
description: `(${SOLUTION_ID}S) - The AWS CloudFormation template for ${SOLUTION_NAME} cross account role, version: ${SOLUTION_VERSION}`,
solutionId: SOLUTION_ID,
solutionTradeMarkName: SOLUTION_TMN,
solutionProvider: SOLUTION_PROVIDER,
Expand Down
2 changes: 1 addition & 1 deletion source/cli/instance-scheduler-cli-runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down
2 changes: 1 addition & 1 deletion source/cli/scheduler_cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down
2 changes: 1 addition & 1 deletion source/cli/scheduler_cli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down
2 changes: 1 addition & 1 deletion source/cli/scheduler_cli/scheduler_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down
2 changes: 1 addition & 1 deletion source/cli/setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down
4 changes: 4 additions & 0 deletions source/lambda/Instance-scheduler.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"ParameterKey": "Trace",
"ParameterValue": "Yes"
},
{
"ParameterKey": "EnableSSMaintenanceWindows",
"ParameterValue": "No"
},
{
"ParameterKey": "TagName",
"ParameterValue": "Schedule"
Expand Down
2 changes: 1 addition & 1 deletion source/lambda/bin/chardetect
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/root/.pyenv/versions/3.8.1/bin/python3.8
#!/root/.pyenv/versions/3.8.8/bin/python3.8
# -*- coding: utf-8 -*-
import re
import sys
Expand Down
11 changes: 6 additions & 5 deletions source/lambda/boto_retry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
######################################################################################################################
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. #
# #
# Licensed under the Apache License Version 2.0 (the "License"). You may not use this file except in compliance #
# with the License. A copy of the License is located at #
Expand Down Expand Up @@ -150,10 +150,11 @@ def get_client_with_retries(service_name, methods, context=None, region=None, se
if region is not None:
args["region_name"] = region

user_agent = os.getenv("USER_AGENT", None)
if user_agent is not None:
session_config = botocore.config.Config(user_agent=user_agent)
args["config"] = session_config
user_agent_extra_string = os.getenv("USER_AGENT_EXTRA", None)
if user_agent_extra_string is not None:
solution_config = {"user_agent_extra": user_agent_extra_string}
config = botocore.config.Config(**solution_config)
args["config"] = config

aws_session = session if session is not None else boto3.Session()

Expand Down
Loading

0 comments on commit d9208dd

Please sign in to comment.