-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path2_build_and_deploy_to_lambda
executable file
·40 lines (33 loc) · 1.86 KB
/
2_build_and_deploy_to_lambda
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
#!/bin/bash
EC2_ID=$(aws cloudformation describe-stack-resources --stack-name node-oracle-lambda-test | \
grep -A 3 AWS::EC2::Instance | grep PhysicalResourceId | sed -E 's/.*"PhysicalResourceId": "([^"]+)".*/\1/')
ADDRESS=$(aws ec2 describe-instances --instance-ids ${EC2_ID} | \
grep -A 5 PrivateIpAddresses | grep '"PrivateIpAddress"' | sed -E 's/.*": "([^"]+)"/\1/')
IDENTITY_FILE=$1
if [[ "${IDENTITY_FILE}" == "" ]]; then
read -e -p $'Enter the path to your identity file (eg ~/.ssh/aws.pem)? ' IDENTITY_FILE
if [ "${IDENTITY_FILE}" == "" ]; then
echo "Need to provide an identity file"
exit 1
fi
fi
#LAMBDA_ROLE_ARN=$(aws iam list-roles | grep Arn.*node-oracledb-lambda-test_execution | sed -E 's/.*"Arn": "([^"]+)".*/\1/')
LAMBDA_ROLE_ARN=$(aws iam list-roles | grep Arn.*node-orac | sed -E 's/.*"Arn": "([^"]+)".*/\1/')
echo LAMBDA_ROLE_ARN: ${LAMBDA_ROLE_ARN}
sed -i "s|LAMBDA_ROLE_ARN=.*|LAMBDA_ROLE_ARN=${LAMBDA_ROLE_ARN}|" 2a_build_and_deploy_to_lambda-remote-script
echo Copying 2a_build_and_deploy_to_lambda-remote-script to ${EC2_ID} at ${ADDRESS}
scp -i ${IDENTITY_FILE} 2a_build_and_deploy_to_lambda-remote-script ec2-user@${ADDRESS}:node-oracledb-lambda-test/2a_build_and_deploy_to_lambda-remote-script
# Restore the local file
sed -i "s|LAMBDA_ROLE_ARN=.*|LAMBDA_ROLE_ARN=(updated by 2_build_and_deploy_to_lambda-remote-script)|" 2a_build_and_deploy_to_lambda-remote-script
echo Connecting by ssh...
ssh ec2-user@${ADDRESS} -i ${IDENTITY_FILE}
# 'bash s' < 2a_build_and_deploy_to_lambda-remote-script
echo Copying app.zip...
scp -i ${IDENTITY_FILE} ec2-user@${ADDRESS}:node-oracledb-lambda-test/app.zip app.zip
#aws lambda create-function \
# --region ap-southeast-2 \
# --function-name node-oracledb-lambda-test \
# --runtime nodejs4.3 \
# --role ${LAMBDA_ROLE_ARN} \
# --handler index.handler \
# --zip-file fileb://app.zip