Skip to content

Update python, nodejs, and codebuild versions. Add AL2023 support #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Cloud9Setup/increase-disk-size.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ then
sudo growpart /dev/xvda 1

# Expand the size of the file system.
# Check if we're on AL2
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
# Check if we're on AL2 or AL2023
STR=$(cat /etc/os-release)
AL2="VERSION_ID=\"2\""
AL2023="VERSION_ID=\"2023\""
if [[ "$STR" =~ "$AL2"|"$AL2023" ]]
then
sudo xfs_growfs -d /
else
Expand All @@ -52,10 +53,11 @@ else
sudo growpart /dev/nvme0n1 1

# Expand the size of the file system.
# Check if we're on AL2
# Check if we're on AL2 or AL2023
STR=$(cat /etc/os-release)
SUB="VERSION_ID=\"2\""
if [[ "$STR" == *"$SUB"* ]]
AL2="VERSION_ID=\"2\""
AL2023="VERSION_ID=\"2023\""
if [[ "$STR" =~ "$AL2"|"$AL2023" ]]
then
sudo xfs_growfs -d /
else
Expand Down
77 changes: 56 additions & 21 deletions Cloud9Setup/pre-requisites.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
#!/bin/bash -x
. /home/ec2-user/.nvm/nvm.sh

#Install python3.8
sudo yum install -y amazon-linux-extras
sudo amazon-linux-extras enable python3.8
sudo yum install -y python3.8
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo alternatives --set python3 /usr/bin/python3.8
STR=$(cat /etc/os-release)
AL2023="VERSION_ID=\"2023\""
IS_AL2023=false

if [[ $STR == *"$AL2023"* ]]; then
echo "AL2023 detected"
IS_AL2023=true
fi

# Install Python 3.11, available as a package on AL2023
PYTHON_VERSION=python3.11
sudo yum install -y "$PYTHON_VERSION"

# Backward compatibility with AL2
if [ $? -ne 0 ]; then
PYTHON_VERSION=python3.8
sudo yum install -y amazon-linux-extras
sudo amazon-linux-extras enable "$PYTHON_VERSION"
sudo yum install -y "$PYTHON_VERSION"
fi

sudo alternatives --install /usr/bin/python3 python3 /usr/bin/"$PYTHON_VERSION" 1
sudo alternatives --set python3 /usr/bin/"$PYTHON_VERSION"

# Check if we are using AL2023, setting python3 breaks dnf and yum
if [[ $IS_AL2023 == true ]]; then
YUM_HEADER=$(head -1 /usr/bin/yum)
DNF_HEADER=$(head -1 /usr/bin/dnf)
PYTH3_HEADER=$'#!/usr/bin/python3'
if [[ "$YUM_HEADER" == "$PYTH3_HEADER" ]]; then
echo "Changing python interpreter for yum to system Python3.9"
sudo sed -i 's|#!/usr/bin/python3|#!/usr/bin/python3.9|g' /usr/bin/yum
fi

if [[ "$DNF_HEADER" == "$PYTH3_HEADER" ]]; then
echo "Changing python interpreter for dnf to system Python3.9"
sudo sed -i 's|#!/usr/bin/python3|#!/usr/bin/python3.9|g' /usr/bin/dnf
fi
fi

# Uninstall aws cli v1 and Install aws cli version-2.3.0
sudo pip2 uninstall awscli -y
Expand All @@ -16,19 +49,19 @@ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-2.3.0.zip" -o "awscli
unzip awscliv2.zip
sudo ./aws/install
rm awscliv2.zip
rm -rf aws
rm -rf aws

# Install sam cli version 1.33.0
echo "Installing sam cli version 1.33.0"
wget https://github.com/aws/aws-sam-cli/releases/download/v1.33.0/aws-sam-cli-linux-x86_64.zip
# Install sam cli version 1.115.0
echo "Installing sam cli version 1.115.0"
wget https://github.com/aws/aws-sam-cli/releases/download/v1.115.0/aws-sam-cli-linux-x86_64.zip
unzip aws-sam-cli-linux-x86_64.zip -d sam-installation
sudo ./sam-installation/install
if [ $? -ne 0 ]; then
echo "Sam cli is already present, so deleting existing version"
sudo rm /usr/local/bin/sam
sudo rm -rf /usr/local/aws-sam-cli
echo "Now installing sam cli version 1.33.0"
sudo ./sam-installation/install
echo "Now installing sam cli version 1.115.0"
sudo ./sam-installation/install
fi
rm aws-sam-cli-linux-x86_64.zip
rm -rf sam-installation
Expand All @@ -41,13 +74,15 @@ rm get-pip.py

python3 -m pip install git-remote-codecommit==1.15.1

# Install node v16.20.0
echo "Installing node v16.20.0"
nvm deactivate
nvm uninstall node
nvm install v16.20.0
nvm use v16.20.0
nvm alias default v16.20.0
if [[ $IS_AL2023 == true ]]; then
# Install node v20.12.2
echo "Installing node v20.12.2"
nvm deactivate
nvm uninstall node
nvm install v20.12.2
nvm use v20.12.2
nvm alias default v20.12.2
fi

# Install cdk cli version ^2.0.0
echo "Installing cdk cli version ^2.0.0"
Expand All @@ -57,7 +92,7 @@ npm install -g aws-cdk@"^2.0.0"
#Install jq version 1.5
sudo yum -y install jq-1.5

#Install pylint version 2.11.1
python3 -m pip install pylint==2.11.1
#Install pylint version 2.17.7
python3 -m pip install pylint==2.17.7

python3 -m pip install boto3
6 changes: 3 additions & 3 deletions server/TenantPipeline/lib/serverless-saas-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class ServerlessSaaSStack extends cdk.Stack {

const lambdaFunctionPrep = new Function(this, "prep-deploy", {
handler: "lambda-prepare-deploy.lambda_handler",
runtime: Runtime.PYTHON_3_9,
runtime: Runtime.PYTHON_3_12,
code: new AssetCode(`./resources`),
memorySize: 512,
timeout: Duration.seconds(10),
Expand Down Expand Up @@ -131,7 +131,7 @@ export class ServerlessSaaSStack extends cdk.Stack {
//Declare a new CodeBuild project
const buildProject = new codebuild.PipelineProject(this, 'Build', {
buildSpec : codebuild.BuildSpec.fromSourceFilename("server/tenant-buildspec.yml"),
environment: { buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_4 },
environment: { buildImage: codebuild.LinuxBuildImage.AMAZON_LINUX_2_5 },
environmentVariables: {
'PACKAGE_BUCKET': {
value: artifactsBucket.bucketName
Expand Down Expand Up @@ -174,7 +174,7 @@ export class ServerlessSaaSStack extends cdk.Stack {

const lambdaFunctionIterator = new Function(this, "WaveIterator", {
handler: "iterator.lambda_handler",
runtime: Runtime.PYTHON_3_9,
runtime: Runtime.PYTHON_3_12,
code: lambda.Code.fromAsset("resources", {exclude: ['*.json']}),
memorySize: 512,
timeout: Duration.seconds(10),
Expand Down
48 changes: 24 additions & 24 deletions server/nested_templates/bootstrap/lambdafunctions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ Resources:
Description: Utilities for project
ContentUri: ../../layers/
CompatibleRuntimes:
- python3.9
- python3.12
LicenseInfo: "MIT"
RetentionPolicy: Retain
Metadata:
BuildMethod: python3.9
BuildMethod: python3.12

#Tenant Authorizer
AuthorizerExecutionRole:
Expand Down Expand Up @@ -135,7 +135,7 @@ Resources:
Properties:
CodeUri: ../../Resources/
Handler: shared_service_authorizer.lambda_handler
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt AuthorizerExecutionRole.Arn
MemorySize: 256
Tracing: Active
Expand All @@ -153,7 +153,7 @@ Resources:
Properties:
CodeUri: ../../Resources/
Handler: tenant_authorizer.lambda_handler
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt AuthorizerExecutionRole.Arn
MemorySize: 256
Tracing: Active
Expand Down Expand Up @@ -246,7 +246,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.create_tenant_admin_user
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt CreateUserLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -289,7 +289,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.create_user
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt CreateUserLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -328,7 +328,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.update_user
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -367,7 +367,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.disable_user
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -405,7 +405,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.disable_users_by_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -443,7 +443,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.enable_users_by_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -481,7 +481,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.get_user
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -519,7 +519,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: user-management.get_users
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantUserPoolLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -597,7 +597,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.create_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -635,7 +635,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.activate_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -675,7 +675,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.get_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -713,7 +713,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.deactivate_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -753,7 +753,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.update_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -795,7 +795,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.get_tenants
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -832,7 +832,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-management.load_tenant_config
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt TenantManagementLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -887,7 +887,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-registration.register_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt RegisterTenantLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -972,7 +972,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-provisioning.provision_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt ProvisionTenantLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -1038,7 +1038,7 @@ Resources:
Properties:
CodeUri: ../../TenantManagementService/
Handler: tenant-provisioning.deprovision_tenant
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt DeProvisionTenantLambdaExecutionRole.Arn
Tracing: Active
Layers:
Expand Down Expand Up @@ -1103,7 +1103,7 @@ Resources:
Properties:
CodeUri: ../../custom_resources/
Handler: update_settings_table.handler
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt UpdateSettingsTableLambdaExecutionRole.Arn
Layers:
- !Ref ServerlessSaaSLayers
Expand Down Expand Up @@ -1140,7 +1140,7 @@ Resources:
Properties:
CodeUri: ../../custom_resources/
Handler: update_tenantstackmap_table.handler
Runtime: python3.9
Runtime: python3.12
Role: !GetAtt UpdateTenantStackMapTableLambdaExecutionRole.Arn
Layers:
- !Ref ServerlessSaaSLayers
Expand Down
2 changes: 1 addition & 1 deletion server/tenant-buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version: 0.2
phases:
install:
runtime-versions:
python: 3.9
python: 3.12
commands:
# Install packages or any pre-reqs in this phase.
# Upgrading SAM CLI to latest version
Expand Down
Loading