Skip to content

Commit

Permalink
Merge branch 'main' into aws-lambda-eventbridge
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh committed Sep 16, 2021
2 parents 54066b8 + 5657b98 commit f9e8a89
Show file tree
Hide file tree
Showing 196 changed files with 1,098 additions and 84,320 deletions.
2 changes: 1 addition & 1 deletion .versionrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"skip": { "tag": true },
"skip": { "tag": true, "commit": true },
"packageFiles": [ { "filename": "source/lerna.json", "type": "json" } ],
"bumpFiles": [ { "filename": "source/lerna.json", "type": "json" } ]
}
37 changes: 18 additions & 19 deletions .viperlightignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,39 @@ source/patterns/@aws-solutions-constructs/aws-cloudfront-apigateway/test/integ.n
source/patterns/@aws-solutions-constructs/aws-apigateway-dynamodb/test/integ.apigateway-dynamodb-existing-table.expected.json:60
CODE_OF_CONDUCT.md:4
CONTRIBUTING.md:244
source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts:114
source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts:124
source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.ts:107
source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/test/test.kinesisstream-gluejob.test.ts:126
source/patterns/@aws-solutions-constructs/aws-lambda-sqs/test/integ.deployFunction.expected.json:112
source/patterns/@aws-solutions-constructs/aws-lambda-sqs/test/integ.existingFunction.expected.json:112
source/patterns/@aws-solutions-constructs/aws-apigateway-sqs/test/integ.apigateway-sqs-crud.expected.json:201
source/tools/cdk-integ-tools/package-lock.json:373
source/patterns/@aws-solutions-constructs/core/test/step-function-helper.test.js:115
source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts:297
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:102
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:102
source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts:219
source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts:186
source/patterns/@aws-solutions-constructs/core/test/lambda-helper.test.ts:233
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:98
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:98
source/patterns/@aws-solutions-constructs/aws-iot-lambda-dynamodb/test/iot-lambda-dynamodb.test.ts:212
source/patterns/@aws-solutions-constructs/aws-lambda-dynamodb/test/lambda-dynamodb.test.ts:180
source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/test/lambda-sqs-lambda.test.ts:66
source/patterns/@aws-solutions-constructs/aws-lambda-sqs-lambda/test/lambda-sqs-lambda.test.ts:67
source/patterns/@aws-solutions-constructs/aws-lambda-step-function/test/lambda-step-function.test.ts:130
source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/test/lambda-stepfunctions.test.ts:130
source/patterns/@aws-solutions-constructs/aws-events-rule-sns/test/events-rule-sns-topic.test.ts:255
source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/test/eventbridge-sns-topic.test.ts:255
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:143
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:143
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:105
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:105
source/patterns/@aws-solutions-constructs/aws-lambda-step-function/test/lambda-step-function.test.ts:125
source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/test/lambda-stepfunctions.test.ts:125
source/patterns/@aws-solutions-constructs/aws-events-rule-sns/test/events-rule-sns-topic.test.ts:248
source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/test/eventbridge-sns-topic.test.ts:248
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:136
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:136
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:103
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:103
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md:39
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/test/integ.defaultParams.expected.json:266
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/test/integ.overrideParams.expected.json:269
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/test/test.apigateway-iot.test.ts:29
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/test/integ.override_auth_api_keys.expected.json:267
source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts:124
source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts:171
source/patterns/@aws-solutions-constructs/aws-cloudfront-s3/test/test.cloudfront-s3.test.ts:118
source/patterns/@aws-solutions-constructs/core/test/cloudfront-distribution-s3-helper.test.ts:164
source/patterns/@aws-solutions-constructs/aws-s3-sqs/test/test.s3-sqs.test.ts:251
source/use_cases/aws-custom-glue-etl/stream-producer/generate_data.py:86
source/use_cases/aws-custom-glue-etl/stream-producer/generate_data.py:87
source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/test/lambda-secretsmanager.test.ts:480
source/patterns/@aws-solutions-constructs/aws-lambda-secretsmanager/test/lambda-secretsmanager.test.ts:460
source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/integ.deployFunction.expected.json:6
source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/integ.deployFunction.expected.json:9
source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/integ.deployFunction.expected.json:12
Expand Down Expand Up @@ -131,7 +130,7 @@ source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/test
source/patterns/@aws-solutions-constructs/aws-lambda-sagemakerendpoint/test/test-helper.ts:84
source/patterns/@aws-solutions-constructs/aws-s3-lambda/test/integ.existing-s3-bucket.expected.json:33
# This is a test case
source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/test/test.kinesisstream-gluejob.test.ts:129
source/patterns/@aws-solutions-constructs/aws-kinesisstreams-gluejob/test/test.kinesisstream-gluejob.test.ts:127
# aws-lambda-eventbridge. Auto generated Ids are ignored & x-ray resource permission with a `*` in test cases is ignored
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.deployFunction.expected.json:122
source/patterns/@aws-solutions-constructs/aws-lambda-eventbridge/test/integ.deployFunctionWithNewEventBus.expected.json:149
Expand Down
Empty file added CHANGELOG.v2.md
Empty file.
12 changes: 11 additions & 1 deletion deployment/bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@
# --------------------------------------------------------------------------------------------------
set -euo pipefail
version=${1:-minor}
deployment_dir=$(cd $(dirname $0) && pwd)

echo "Starting ${version} version bump"

# Generate CHANGELOG and create a commit
npx standard-version --release-as ${version}
npx standard-version --release-as ${version}

# Disabled the autocommit of 'standard-version' due to faulty CHANGELOG.md updates during CDK v2 build
# and hence need to run git add/commit commands outside of 'standard-version'
repoVersion=$(node -p "require('${deployment_dir}/get-version')")
echo "repoVersion=${repoVersion}"

git add source/lerna.json
git add CHANGELOG.md
git commit -m "chore(release): ${repoVersion}"
70 changes: 70 additions & 0 deletions deployment/v2/align-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env node
// It will make following updates to package.json
// 1 - align the version in a package.json file to the version of the repo
// 2 - Remove all entries starting with @aws-cdk/* and constructs from "dependencies": { ... }
// 3 - Remove all entries starting with @aws-cdk/* and constructs from "peerDependencies": { ... }, Add { "aws-cdk-lib": "^2.0.0-rc.1", "constructs": "^10.0.0" }
// 4 - Add { "aws-cdk-lib": "2.0.0-rc.1", "constructs": "^10.0.0" } to "devDependencies"
const fs = require('fs');

const findVersion = process.argv[2];
const replaceVersion = process.argv[3];

// these versions need to be sourced from a config file
const awsCdkLibVersion = '2.0.0-rc.16';
const constructsVersion = '10.0.0';

for (const file of process.argv.splice(4)) {
const pkg = JSON.parse(fs.readFileSync(file).toString());

if (pkg.version !== findVersion && pkg.version !== replaceVersion) {
throw new Error(`unexpected - all package.json files in this repo should have a version of ${findVersion} or ${replaceVersion}: ${file}`);
}

pkg.version = replaceVersion;

pkg.dependencies = processDependencies(pkg.dependencies || { }, file);
pkg.peerDependencies = processPeerDependencies(pkg.peerDependencies || { }, file);
pkg.devDependencies = processDevDependencies(pkg.devDependencies || { }, file);

console.error(`${file} => ${replaceVersion}`);
fs.writeFileSync(file, JSON.stringify(pkg, undefined, 2));

}

function processDependencies(section, file) {
let newdependencies = {};
for (const [ name, version ] of Object.entries(section)) {
// Remove all entries starting with @aws-cdk/* and constructs
if (!name.startsWith('@aws-cdk/') && !name.startsWith('constructs')) {
newdependencies[name] = version.replace(findVersion, replaceVersion);
}
}
return newdependencies;
}

function processPeerDependencies(section, file) {
let newdependencies = {};
for (const [ name, version ] of Object.entries(section)) {
// Remove all entries starting with @aws-cdk/* and constructs
if (!name.startsWith('@aws-cdk/') && !name.startsWith('constructs')) {
newdependencies[name] = version.replace(findVersion, replaceVersion);
}
}
newdependencies["aws-cdk-lib"] = `^${awsCdkLibVersion}`;
newdependencies["constructs"] = `^${constructsVersion}`;
return newdependencies;
}

function processDevDependencies(section, file) {
let newdependencies = section;
for (const [ name, version ] of Object.entries(newdependencies)) {
// Remove all entries starting with @aws-cdk/* and constructs
if (version === findVersion || version === '^' + findVersion) {
newdependencies[name] = version.replace(findVersion, replaceVersion);
}
}
// note: no ^ to make sure we test against the minimum version
newdependencies["aws-cdk-lib"] = `${awsCdkLibVersion}`;
newdependencies["constructs"] = `^${constructsVersion}`;
return newdependencies;
}
24 changes: 24 additions & 0 deletions deployment/v2/align-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -euo pipefail

deployment_dir=$(cd $(dirname $0) && pwd)
source_dir="$deployment_dir/../../source"

cd $deployment_dir
# Retrieve version numbers for marker and repo
marker=$(node -p "require('./get-version-marker')")
repoVersion=$(node -p "require('./get-version')")

cd $source_dir/

# Align versions in ALL package.json with the one in lerna.json
files=$(find . -name package.json |\
grep -v node_modules)

if [ $# -eq 0 ]; then
echo "Updating ALL package.json for CDK v2"
${deployment_dir}/align-version.js ${marker} ${repoVersion} ${files}
else
echo "Reverting back CDK v2 updatesfrom ALL package.json files"
git checkout `find . -name package.json | grep -v node_modules`
fi
83 changes: 83 additions & 0 deletions deployment/v2/build-cdk-dist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
set -euo pipefail

deployment_dir=$(cd $(dirname $0) && pwd)
source_dir="$deployment_dir/../source"
dist_dir="$deployment_dir/dist"

cd $source_dir/
export PATH=$(npm bin):$PATH
export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"

cd $deployment_dir/

echo "------------------------------------------------------------------------------"
echo "[Copy] CDK templates for all patterns into the deployment dir for CfnNagScan"
echo "------------------------------------------------------------------------------"

echo "mkdir -p $dist_dir"
mkdir -p $dist_dir

for subdir in $source_dir/patterns/\@aws-solutions-constructs/* ; do
if [ -d "$subdir" -a `basename $subdir` != "node_modules" ]; then
cd $subdir/test

echo "Checking integ CFN templates in $subdir/test"
cnt=`find . -name "*expected.json" -type f | wc -l`
prefix=`basename $subdir`
if [ "$prefix" != "core" ]
then
if [ "$cnt" -eq "0" ]
then
echo "************** [ERROR] ************* Did not find any integ CFN templates in $subdir; please add atleast one by writing an integ test case and running cdk-integ command to generate the CFN template for it"
exit 1
fi
fi

echo "Copying templates from $subdir/test"
for i in `find . -name "*expected.json" -type f`; do
prefix=`basename $subdir`
suffix=`basename $i`
cp $subdir/test/$i $dist_dir/$prefix-$suffix.template
done
cd $source_dir
fi
done

echo "------------------------------------------------------------------------------"
echo "[Copy] packages for all patterns into the deployment dir"
echo "------------------------------------------------------------------------------"

echo "mkdir -p $dist_dir"
mkdir -p $dist_dir

for dir in $(find $source_dir/patterns/\@aws-solutions-constructs/ -name dist | grep -v node_modules | grep -v coverage); do
echo "Merging ${dir} into ${dist_dir}" >&2
rsync -a $dir/ ${dist_dir}/
done

echo "------------------------------------------------------------------------------"
echo "[Create] build.json file"
echo "------------------------------------------------------------------------------"
# Get commit hash from CodePipeline env variable CODEBUILD_RESOLVED_SOURCE_VERSION
echo $deployment_dir
version=$(node -p "require('$deployment_dir/get-version.js')")
commit="${CODEBUILD_RESOLVED_SOURCE_VERSION:-}"

cat > ${dist_dir}/build.json <<HERE
{
"name": "aws-solutions-constructs",
"version": "${version}",
"commit": "${commit}"
}
HERE

# copy CHANGELOG.md to dist/ for github releases
changelog_file=$deployment_dir/../CHANGELOG.md
cp ${changelog_file} ${dist_dir}/CHANGELOG.md

echo "------------------------------------------------------------------------------"
echo "[List] deployment/dist contents"
echo "------------------------------------------------------------------------------"

find $dist_dir
47 changes: 47 additions & 0 deletions deployment/v2/build-patterns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -euo pipefail

deployment_dir=$(cd $(dirname $0) && pwd)
source_dir="$deployment_dir/../../source"

echo "============================================================================================="
echo "aligning versions and updating package.json for CDK v2..."
/bin/bash $deployment_dir/align-version.sh

echo "============================================================================================="
echo "updating Import statements for CDK v2..."
/bin/bash $deployment_dir/rewrite-imports.sh

echo "============================================================================================="
echo "building cdk-integ-tools..."
cd $source_dir/tools/cdk-integ-tools
npm install
npm run build
npm link

bail="--bail"
runtarget="build+lint+test"
cd $source_dir/

export PATH=$(npm bin):$PATH
export NODE_OPTIONS="--max-old-space-size=4096 ${NODE_OPTIONS:-}"

echo "============================================================================================="
echo "installing..."
yarn install --frozen-lockfile

echo "============================================================================================="
echo "building..."
time lerna run $bail --stream $runtarget || fail

echo "============================================================================================="
echo "packaging..."
time lerna run --bail --stream jsii-pacmak || fail

echo "============================================================================================="
echo "reverting back versions and updates to package.json for CDK v2..."
/bin/bash $deployment_dir/align-version.sh revert

echo "============================================================================================="
echo "reverting back Import statements for CDK v2..."
/bin/bash $deployment_dir/rewrite-imports.sh revert
66 changes: 66 additions & 0 deletions deployment/v2/bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
# --------------------------------------------------------------------------------------------------
#
# This script is intended to be used to bump the version of the CDK modules, update package.json,
# package-lock.json, and create a commit.
#
# to start a version bump, run:
# bump.sh <version | version Type>
#
# If a version is not provided, the 'minor' version will be bumped.
# The version can be an explicit version _or_ one of:
# 'major', 'minor', 'patch', 'premajor', 'preminor', 'prepatch', or 'prerelease'.
#
# --------------------------------------------------------------------------------------------------
set -euo pipefail
version=${1:-prerelease}
deployment_dir=$(cd $(dirname $0) && pwd)

echo "Starting ${version} version bump"
echo "Loading ${deployment_dir}/get-version"

# Rename CHANGELOG.md
echo "Rename CHANGELOG.md to CHANGELOG.md.bak"
mv CHANGELOG.md CHANGELOG.md.bak
echo "Rename CHANGELOG.v2.md to CHANGELOG.md"
mv CHANGELOG.v2.md CHANGELOG.md

# Rename lerna.json
echo "Rename source/lerna.json to source/lerna.json.bak"
mv source/lerna.json source/lerna.json.bak
echo "Rename source/lerna.v2.json to source/lerna.json"
mv source/lerna.v2.json source/lerna.json

# `standard-release` will -- among other things -- create the changelog.
# However, on the v2 branch, `conventional-changelog` (which `standard-release` uses) gets confused
# and creates really muddled changelogs with both v1 and v2 releases intermingled, and lots of missing data.
# A super HACK here is to locally remove all version tags that don't match this major version prior
# to doing the bump, and then later fetching to restore those tags.
git tag -d `git tag -l | grep -v '^v2.'`

# Generate CHANGELOG and create a commit
npx standard-version --release-as ${version}

# fetch back the tags, and only the tags, removed locally above
git fetch origin "refs/tags/*:refs/tags/*"

# Restore CHANGELOG.md
echo "Rename CHANGELOG.md to CHANGELOG.v2.md"
mv CHANGELOG.md CHANGELOG.v2.md
echo "Rename CHANGELOG.md.bak to CHANGELOG.md"
mv CHANGELOG.md.bak CHANGELOG.md

# Restore lerna.json
echo "Rename source/lerna.json to source/lerna.v2.json"
mv source/lerna.json source/lerna.v2.json
echo "Rename source/lerna.json.bak to source/lerna.json"
mv source/lerna.json.bak source/lerna.json

# Disabled the autocommit of 'standard-version' due to faulty CHANGELOG.md updates during CDK v2 build
# and hence need to run git add/commit commands outside of 'standard-version'
repoVersion=$(node -p "require('${deployment_dir}/get-version')")
echo "repoVersion=${repoVersion}"

git add source/lerna.v2.json
git add CHANGELOG.v2.md
git commit -m "chore(release): ${repoVersion}"
Loading

0 comments on commit f9e8a89

Please sign in to comment.