From 7c4a0c0288d68c77d6416c2410545c579bde31e5 Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Mon, 7 Nov 2022 16:17:16 +0530 Subject: [PATCH 1/9] lambda test 1 --- Jenkinsfile | 20 ++++++++++++++++++++ ci/lambda-test.sh | 18 ++++++++++++++++++ lambda-function.zip | Bin 0 -> 322 bytes 3 files changed, 38 insertions(+) create mode 100644 Jenkinsfile create mode 100644 ci/lambda-test.sh create mode 100644 lambda-function.zip diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..b3a7536 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,20 @@ +pipeline { + agent any + stages { + stage('Staging DB migration') { + when { branch 'develop'} + stage('Lambda Deployment') { + when { branch 'lambda-test' } + steps { + timeout(time: 100, unit: 'SECONDS') { + input "Lambda Source Code Deployment ?" + } + script { + def AWS_PROFILE = 'cd-sandbox' + def DEPLOY_ROLE = 'arn:aws:iam::221283034294:role/deploy_role' + sh "source ci/assume_role.sh ${DEPLOY_ROLE} ${AWS_PROFILE}" + } + } + } + } +} \ No newline at end of file diff --git a/ci/lambda-test.sh b/ci/lambda-test.sh new file mode 100644 index 0000000..02703f5 --- /dev/null +++ b/ci/lambda-test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +ROLE_ARN=$1 +AWS_PROFILE=$2 +ROLE_SESSION_NAME=lambda-deployment + +# this assumes that the ecr_login has been done before which gives the docker container access to the production server deployment role +CREDENTIALS=`aws sts assume-role --role-arn $1 --role-session-name $ROLE_SESSION_NAME --profile $2` +export AWS_ACCESS_KEY_ID=`echo $CREDENTIALS | jq -r .Credentials.AccessKeyId` +export AWS_SECRET_ACCESS_KEY=`echo $CREDENTIALS | jq -r .Credentials.SecretAccessKey` +export AWS_SESSION_TOKEN=`echo $CREDENTIALS | jq -r .Credentials.SessionToken` +export AWS_DEFAULT_REGION='us-east-1' + +echo $AWS_ACCESS_KEY_ID +echo $AWS_SECRET_ACCESS_KEY +echo $AWS_SESSION_TOKEN + +aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://../lambda-function.zip \ No newline at end of file diff --git a/lambda-function.zip b/lambda-function.zip new file mode 100644 index 0000000000000000000000000000000000000000..5ba0bd7470407dfbed1ff936f29254025d1ebb8f GIT binary patch literal 322 zcmWIWW@Zs#U|`^2SR0le>NxL;(i|Y~9#}+%Au}%}wL&keI5dQlf!S|bMluMOR&X;g zvbSgb}1ugoeZuJh{_Z_A#RQ4qHHJ5#1tgIluDjbk7E*Vj$`_v`)C{L6~{ zeRk#93zFJbO<#5VfuIdzfHxzP95XKeNdSGxz`zK^TN*(ugl}0PzD4tCfHx}}NF5^( M`T=QBC^0Yq02#?{9RL6T literal 0 HcmV?d00001 From 0805d88fa01334543dbab893539d7011355d54bc Mon Sep 17 00:00:00 2001 From: Sampath Kumar <107537331+Sampath8797@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:49:26 +0530 Subject: [PATCH 2/9] using export profile --- Jenkinsfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b3a7536..93cec7f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,10 +11,11 @@ pipeline { } script { def AWS_PROFILE = 'cd-sandbox' - def DEPLOY_ROLE = 'arn:aws:iam::221283034294:role/deploy_role' - sh "source ci/assume_role.sh ${DEPLOY_ROLE} ${AWS_PROFILE}" + sh "export AWS_PROFILE=cd-sandbox" + sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" } } } } -} \ No newline at end of file + } +} From 52691364d2c2429956804811f8be81d57d280cd6 Mon Sep 17 00:00:00 2001 From: Sampath Kumar <107537331+Sampath8797@users.noreply.github.com> Date: Mon, 7 Nov 2022 17:56:52 +0530 Subject: [PATCH 3/9] Update Jenkinsfile --- Jenkinsfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 93cec7f..cf13394 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,21 +1,17 @@ pipeline { agent any stages { - stage('Staging DB migration') { - when { branch 'develop'} stage('Lambda Deployment') { - when { branch 'lambda-test' } + when { branch 'develop' } steps { timeout(time: 100, unit: 'SECONDS') { input "Lambda Source Code Deployment ?" } script { - def AWS_PROFILE = 'cd-sandbox' sh "export AWS_PROFILE=cd-sandbox" sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" } } - } } } } From d4354f126bcd16a56a7a52e576da98b19064ecb7 Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 09:14:57 +0530 Subject: [PATCH 4/9] pipeline updated --- Jenkinsfile | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index cf13394..5d3ee7c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,17 +1,18 @@ pipeline { agent any stages { - stage('Lambda Deployment') { - when { branch 'develop' } - steps { - timeout(time: 100, unit: 'SECONDS') { - input "Lambda Source Code Deployment ?" - } - script { - sh "export AWS_PROFILE=cd-sandbox" - sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" - } - } + stage('Lambda Deployment') { + when { branch 'develop'} + steps { + timeout(time: 150, unit: 'seconds') { + input "Replace Lambda Source Code ?" + } + script { + sh "export AWS_PROFILE=cd-sandbox" + sh "aws --version" + sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" + } + } } } -} +} \ No newline at end of file From f61d9413b1ce4eac1466679418559bc163c54dd1 Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 09:19:45 +0530 Subject: [PATCH 5/9] SECONDS --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5d3ee7c..78b9ca1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,7 +4,7 @@ pipeline { stage('Lambda Deployment') { when { branch 'develop'} steps { - timeout(time: 150, unit: 'seconds') { + timeout(time: 150, unit: 'SECONDS') { input "Replace Lambda Source Code ?" } script { From 3cdc435cc426485bc254666270ccee13a8c6ba56 Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 09:22:27 +0530 Subject: [PATCH 6/9] region --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 78b9ca1..680348e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { script { sh "export AWS_PROFILE=cd-sandbox" sh "aws --version" - sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" + sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip --region us-east-1" } } } From 23ef3aa47053be9ae12d5746b485cf24e0cad11c Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 09:25:05 +0530 Subject: [PATCH 7/9] s3 ls --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 680348e..382c23c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,6 +10,7 @@ pipeline { script { sh "export AWS_PROFILE=cd-sandbox" sh "aws --version" + sh "aws s3 ls" sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip --region us-east-1" } } From bc8097bf46365e420b5d356d31a6e982400f7f3f Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 10:31:37 +0530 Subject: [PATCH 8/9] Profile configured --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 382c23c..50b6bb0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,9 @@ pipeline { - agent any + agent{ + node{ + label 'Built-In' + } + } stages { stage('Lambda Deployment') { when { branch 'develop'} @@ -10,8 +14,7 @@ pipeline { script { sh "export AWS_PROFILE=cd-sandbox" sh "aws --version" - sh "aws s3 ls" - sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip --region us-east-1" + sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" } } } From 0fbf6eb5d46badf780b7f0af2feab4434454191f Mon Sep 17 00:00:00 2001 From: Sampath8797 Date: Tue, 8 Nov 2022 10:36:46 +0530 Subject: [PATCH 9/9] rgion added --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 50b6bb0..add6849 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,8 @@ pipeline { script { sh "export AWS_PROFILE=cd-sandbox" sh "aws --version" - sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip" + + sh "aws lambda update-function-code --function-name lambda-automation-test --zip-file fileb://lambda-function.zip --region us-east-1" } } }