Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

remove type block code in tools/* and update payment-3p to use aws cli V2 #229

Open
wants to merge 5 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
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,58 @@ _Please note that you may incure AWS charges for deploying the ecommerce platfor

To install the necessary tools and deploy this in your own AWS account, see the [getting started](docs/getting_started.md) guide in the documentation section.

--------------------------------------------START CUSTOM PIPELINE ---------------------------------------------
### Deploy without Makefile on LINUX/Ubuntu OS
For the purpose of learning, we will build, package and deploy project in aws account using the scripts in the [tools] folder on linux system

##### Run pipeline on services
* [cd project_root](aws-serverless-ecommerce-platform)

###### Build services
* ./tools/build resources SERVICE
* ./tools/build openapi SERVICE
* ./tools/build python3 SERVICE
* ./tools/build cloudformation SERVICE

###### Check-deps services
* ./tools/check-deps cloudformation SERVICE

###### Clean services
* ./tools/clean SERVICE

###### Deploy services
* ./tools/deploy cloudformation SERVICE

###### Lint services
* ./tools/lint cloudformation ${SERVICE}
* ./tools/lint python3 SERVICE
* ./tools/lint openapi SERVICE

###### Package services
* ./tools/package cloudformation SERVICE

###### Teardown services
* ./tools/teardown cloudformation SERVICE

###### Integration tests
* ./tools/tests-integ cloudformation SERVICE

###### Unit tests
* ./tools/tests-unit python3 SERVICE

###### End-to-end tests
[ENVIRONMENT=dev](/tools/tests-e2e)
* ./tools/tests-e2e

###### Automation
We use script [package_services.sh](@root/package_services.sh) and [deploy_services.sh](@root/deploy_services.sh) for automate
[cd project_root](aws-serverless-ecommerce-platform)

* $ ./package_services.sh SERVICE
* $ ./deploy_services.sh SERVICE

--------------------------------------------END CUSTOM PIPELINE ---------------------------------------------

## Architecture

### High-level architecture
Expand Down
3 changes: 2 additions & 1 deletion delivery-pricing/src/pricing/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
aws-lambda-powertools==1.16.1
../shared/src/ecom/
shared/src/ecom/

3 changes: 2 additions & 1 deletion delivery/src/table_update/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aws-lambda-powertools==1.16.1
boto3
../shared/src/ecom/
shared/src/ecom/

1 change: 0 additions & 1 deletion delivery/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ Resources:
# delivery/build folder, not the delivery folder.
TemplateURL: ../../shared/templates/dlq.yaml


#############
# DASHBOARD #
#############
Expand Down
16 changes: 16 additions & 0 deletions deploy_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

#Get the list of services
#services=$(./tools/services --graph --env-only)

#Iterate over each service and deploy it
echo "============= #Iterate over each service and deploy it ==="

while read -r services; do
IFS=',' read -ra service_array <<< "$services"
for service in "${service_array[@]}";do
./tools/deploy cloudformation "$service"
done
done <<< "$(./tools/services --graph --env-only)"

echo "all services deploy to aws cloud"
6 changes: 5 additions & 1 deletion environments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ dev:
parameters:
LogLevel: DEBUG
RetentionInDays: "7"
flags:
can-tests-integ: true
can-tests-e2e: true


tests:
parameters:
Expand All @@ -21,5 +25,5 @@ prod:
RetentionInDays: "30"
flags:
can-tests-integ: false
can-tests-e2e: false
can-tests-e2e: true
is-prod: true
3 changes: 2 additions & 1 deletion orders/src/get_order/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aws-lambda-powertools==1.16.1
boto3
../shared/src/ecom/
shared/src/ecom/

3 changes: 2 additions & 1 deletion orders/src/table_update/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aws-lambda-powertools==1.16.1
boto3
../shared/src/ecom/
shared/src/ecom/

1 change: 1 addition & 0 deletions orders/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ Resources:
# The path starts with '../..' as this will be evaluated from the
# orders/build folder, not the orders folder.
TemplateURL: ../../shared/templates/dlq.yaml

Parameters:
AlarmAction: !Ref AlarmTopic

Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 85 additions & 0 deletions package_services.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

SERVICE="$1" # arg passed to the script

if [ -z "$SERVICE" ]; then
echo "Usage: $0 <service>"
exit 1
fi

# Function to check if the last command executed successfully
check_error() {
if [ $? -ne 0 ]; then
echo "Error occured. Existing .."
exit 1
fi
}

echo "================= CLEAN SERVICE ================"
./tools/clean "$SERVICE"
check_error

# Evaluate if SERVICE equals "payment-3p"
if [ "$SERVICE" == "payment-3p" ]; then
cd payment-3p/ || exit 1
# Copy files to the build folder
if [ ! -d build/ ]; then
mkdir build/
fi

cp -rp src/ build/src/

npx cdk synth --verbose > build/template.yaml

# Save the current directory
CURDIR=$(pwd)

# Install packages and transpile to Javascript for each Lambda function
for function_folder in build/src/* ; do
cd "$function_folder" || exit
npm i
cd "$CURDIR" || exit
npx tsc -p "$function_folder"
done

cd ../ || exit 1
else
echo "============ BUILD RESOUCES SERVICE =============="
./tools/build resources "$SERVICE"
check_error

echo "============ BUILD OPENAPI SERVICE =============="
./tools/build openapi "$SERVICE"
check_error

echo "============ BUILD PYTHON3 SERVICE =============="
./tools/build python3 "$SERVICE"
check_error
fi

echo "============ BUILD CLOUDFORMATION SERVICE =============="
./tools/build cloudformation "$SERVICE"
check_error

if [ ! "$SERVICE" == "payment-3p" ]; then
echo "============ LINT CLOUDFORMATION SERVICE =============="
./tools/lint cloudformation "$SERVICE"
check_error

echo "============ TESTS-UNIT PYTHON3 SERVICE =============="
./tools/tests-unit python3 "$SERVICE"
check_error
fi



echo "============ PACKAGE CLOUDFORMATION SERVICE =============="
./tools/package cloudformation "$SERVICE"
check_error

echo "============ CHECK-DEPS CLOUDFORMATION SERVICE =============="
./tools/check-deps cloudformation "$SERVICE" &
check_error

wait
echo "Ready to deploy : $SERVICE "
5 changes: 1 addition & 4 deletions payment-3p/.gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
*.js
!*jest.config.js
!jest.config.js
*.d.ts
node_modules

# CDK asset staging directory
.cdk.staging
cdk.out

# Prevent ignoring the 'lib' folder
!lib
5 changes: 2 additions & 3 deletions payment-3p/bin/payment-3p.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import * as cdk from 'aws-cdk-lib';
import { Payment3PStack } from '../lib/payment-3p-stack';

const app = new cdk.App();
new Payment3PStack(app, 'Payment3PStack');
app.synth();
new Payment3PStack(app, 'Payment3PStack');
4 changes: 0 additions & 4 deletions payment-3p/cdk.context.json

This file was deleted.

9 changes: 0 additions & 9 deletions payment-3p/cdk.jest.config.js

This file was deleted.

71 changes: 70 additions & 1 deletion payment-3p/cdk.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,72 @@
{
"app": "npx ts-node bin/payment-3p.ts"
"app": "npx ts-node --prefer-ts-exts bin/payment-3p.ts",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"**/*.d.ts",
"**/*.js",
"tsconfig.json",
"package*.json",
"yarn.lock",
"node_modules",
"test"
]
},
"context": {
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
"@aws-cdk/core:checkSecretUsage": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
],
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
"@aws-cdk/aws-iam:minimizePolicies": true,
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
"@aws-cdk/core:enablePartitionLiterals": true,
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
"@aws-cdk/aws-route53-patters:useCertificate": true,
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
"@aws-cdk/aws-redshift:columnId": true,
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
"@aws-cdk/aws-kms:aliasNameRef": true,
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false
}
}
10 changes: 0 additions & 10 deletions payment-3p/integ.jest.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions payment-3p/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/test'],
testMatch: ['**/*.test.ts'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
}
};
17 changes: 9 additions & 8 deletions payment-3p/lib/payment-3p-stack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as cdk from '@aws-cdk/core';
import * as logs from '@aws-cdk/aws-logs';
import * as sam from '@aws-cdk/aws-sam';
import * as ssm from '@aws-cdk/aws-ssm';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
import * as cdk from 'aws-cdk-lib';
import * as logs from 'aws-cdk-lib/aws-logs';
import * as sam from 'aws-cdk-lib/aws-sam';
import * as ssm from 'aws-cdk-lib/aws-ssm';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import { Construct } from 'constructs';

const API_STAGE_NAME = "prod";
const FUNCTION_RUNTIME = "nodejs12.x";
const FUNCTION_RUNTIME = "nodejs18.x";
const SERVICE_NAME = "payment-3p";

export class Payment3PStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// Parameters
Expand Down Expand Up @@ -219,4 +220,4 @@ export class Payment3PStack extends cdk.Stack {
retention: 30 //retentionInDays.valueAsNumber
});
}
}
}
Loading