forked from aws-samples/sagemaker-mlops-with-tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-cfn.sh
executable file
·75 lines (59 loc) · 2.42 KB
/
deploy-cfn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
set -e
# This script will create an S3 seedcode bucket ad lambda layer files.
# It will zip files and load to the S3 bucket.
# It will also deploy the CloudFormation template that will provision AWS services.
# This script assumes a Linux or MacOSX environment and relies on the following software packages being installed:
# . - AWS Command Line Interface (CLI)
# . - sed
# . - Python 3 / pip3
# . - zip
# . - Docker
date=`date +"%Y-%m-%d"`
today=$(date +"%Y-%m-%d")
echo "${today}"
#Provide your own parameters
SEED_BUCKET_NAME="tf-cicd-lambda-seed-${today}"
UPLOAD_DIR="upload_to_s3"
CFN_TEMPLATE="CF-MLOps-TensorFlow-Pipeline.yml"
DEPLOYMENT_REGION="us-east-1"
STACK_NAME="MLOps-TensorFlow-FrameWork-CICD"
#3-letter unique id. INPUT YOUR OWN ID
Unique_ID="<YOUR ID>"
UPLOAD_LST="MLOps-tf-EvaluateModel.py.zip MLOps-tf-DeployModel.py.zip MLOps-tf-GetStatus.py.zip MLOps-tf-PrepareData.py.zip MLOps-tf-TrainModel.py.zip pandas_layer.zip seedcode.zip"
echo "Create s3 bucket"
# Check that S3 bucket exists, if not create a new one
if aws s3 ls s3://${SEED_BUCKET_NAME} 2>&1 | grep NoSuchBucket
then
echo Creating Amazon S3 bucket ${SEED_BUCKET_NAME}
aws s3 mb s3://${SEED_BUCKET_NAME} --region $DEPLOYMENT_REGION
fi
echo "Create lambda layer files using docker"
#Use docker to create lambda layer file
docker run -v "$PWD":/var/task "public.ecr.aws/sam/build-python3.7" /bin/sh -c "pip install -r requirements.txt -t lambda_layer/python/lib/python3.7/site-packages/; exit"
echo "Zip files"
mkdir -p ${UPLOAD_DIR}
(cd seedcode ; zip -r ../${UPLOAD_DIR}/seedcode.zip . )
(cd lambda_layer ; zip -r ../${UPLOAD_DIR}/pandas_layer.zip python )
(cd lambda
for fname in *.py;
do
zip ../${UPLOAD_DIR}/${fname}.zip ${fname}
done
)
# push files to S3, note this does not 'package' the templates
echo "Copying LAMBDA AND SEED files to S3: ${UPLOAD_LST}"
for fname in ${UPLOAD_LST};
do
aws s3 cp ${UPLOAD_DIR}/${fname} s3://${SEED_BUCKET_NAME}/${fname}
done
echo "LAMBDA AND SEED CODE UPLOADED"
aws cloudformation deploy \
--template-file ${CFN_TEMPLATE} \
--stack-name ${STACK_NAME} \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides "UniqueID"=${Unique_ID} "LambdaSeedBucket"=${SEED_BUCKET_NAME}
echo ==================================================
echo "Deoployment complete."