@webdevcody/liftoff
Advanced tools
| #!/bin/bash -e | ||
| rm -rf out | ||
| rm -rf tmp | ||
| rm -rf dist |
| #!/bin/bash -e | ||
| AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | ||
| FUNCTION_NAME="$APP_PREFIX-lambda-function" | ||
| API_NAME="$APP_PREFIX-api-gateway" | ||
| FUNCTION_ARN="arn:aws:lambda:$REGION:$AWS_ACCOUNT_ID:function:$APP_PREFIX-lambda-function" | ||
| # Check if API Gateway already exists | ||
| EXISTING_API=$(aws apigatewayv2 get-apis --query "Items[?Name=='$API_NAME']") | ||
| echo "EXISTING_API $EXISTING_API" | ||
| if [ "$EXISTING_API" == "[]" ]; then | ||
| # Create an API Gateway REST API | ||
| API_ID=$(aws apigatewayv2 create-api --name $API_NAME --protocol-type HTTP --target $FUNCTION_ARN | jq -r '.ApiId') | ||
| # Create an API Gateway Integration | ||
| INTEGRATION_ID=$(aws apigatewayv2 create-integration --api-id $API_ID --integration-type AWS_PROXY --integration-uri $FUNCTION_ARN --integration-method ANY --payload-format-version 2.0 | jq -r '.IntegrationId') | ||
| # Create an API Gateway Route | ||
| ROUTE_ID=$(aws apigatewayv2 create-route --api-id $API_ID --route-key "ANY /{proxy+}" --target "integrations/$INTEGRATION_ID" | jq -r '.RouteId') | ||
| # Deploy the API Gateway | ||
| DEPLOYMENT_ID=$(aws apigatewayv2 create-deployment --api-id $API_ID --description "Initial deployment" | jq -r '.DeploymentId') | ||
| # Add permissions to Lambda function to allow API Gateway to invoke it | ||
| aws lambda add-permission \ | ||
| --function-name $FUNCTION_NAME \ | ||
| --statement-id "apigateway-test-1" \ | ||
| --action "lambda:InvokeFunction" \ | ||
| --principal apigateway.amazonaws.com \ | ||
| --source-arn "arn:aws:execute-api:$REGION:$AWS_ACCOUNT_ID:$API_ID/*/*/*" | ||
| # Print out the API Gateway URL | ||
| URL="https://$API_ID.execute-api.$REGION.amazonaws.com/$DEPLOYMENT_ID" | ||
| echo "API Gateway URL: $URL" | ||
| else | ||
| echo "Api already exists, skipping" | ||
| fi |
+2
-3
| { | ||
| "name": "@webdevcody/liftoff", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "description": "", | ||
@@ -15,4 +15,3 @@ "main": "index.js", | ||
| "author": "", | ||
| "license": "MIT", | ||
| "dependencies": {} | ||
| "license": "MIT" | ||
| } |
+12
-13
| #!/bin/bash -e | ||
| if [[ -z "$APP_PREFIX" ]]; then | ||
| echo "Error: APP_PREFIX environment variable is not defined" | ||
| exit 1 | ||
| fi | ||
| # Define the name of the Lambda function | ||
@@ -15,5 +9,2 @@ FUNCTION_NAME="$APP_PREFIX-lambda-function" | ||
| # Define the AWS region where the function will be created | ||
| AWS_REGION="us-east-1" | ||
| # Define the name of the IAM role that the function will use | ||
@@ -44,6 +35,6 @@ IAM_ROLE_NAME="$APP_PREFIX-lambda-role" | ||
| --zip-file "fileb://$ZIP_FILE_PATH" \ | ||
| --region "$AWS_REGION" | ||
| --region "$REGION" | ||
| # Publish a new version of the function | ||
| while ! aws lambda publish-version --function-name "$FUNCTION_NAME" --region "$AWS_REGION" --output text --query 'Version'; do | ||
| while ! aws lambda publish-version --function-name "$FUNCTION_NAME" --region "$REGION" --output text --query 'Version'; do | ||
| echo "Retrying publish-version command in 5 seconds..." | ||
@@ -61,6 +52,14 @@ sleep 5 | ||
| --zip-file "fileb://$ZIP_FILE_PATH" \ | ||
| --region "$AWS_REGION" | ||
| --region "$REGION" | ||
| fi | ||
| # Load environment variables from .env.prod file | ||
| source .env.prod | ||
| # Verify that the function was created successfully | ||
| aws lambda get-function --function-name "$FUNCTION_NAME" --region "$AWS_REGION" | ||
| aws lambda get-function --function-name "$FUNCTION_NAME" --region "$REGION" | ||
| aws lambda update-function-configuration \ | ||
| --function-name $FUNCTION_NAME \ | ||
| --environment Variables="{`cat .env.prod | xargs | sed 's/ /,/g'`}" | ||
+17
-9
| #!/bin/bash -e | ||
| if [[ -z "$APP_PREFIX" ]]; then | ||
| echo "Error: APP_PREFIX environment variable is not defined" | ||
| exit 1 | ||
| fi | ||
| # Define required environment variables | ||
| REQUIRED_VARS=("APP_PREFIX" "REGION") | ||
| if [[ -z "$REGION" ]]; then | ||
| echo "Error: REGION environment variable is not defined" | ||
| exit 1 | ||
| # Loop through the required variables and check if they are defined | ||
| for VAR in "${REQUIRED_VARS[@]}" | ||
| do | ||
| if [[ -z "${!VAR}" ]]; then | ||
| echo "Error: ${VAR} environment variable is not defined" | ||
| MISSING_VARS=true | ||
| fi | ||
| done | ||
| # Exit with an error if any required variables are missing | ||
| if [ "${MISSING_VARS}" = true ]; then | ||
| exit 1 | ||
| fi | ||
@@ -16,3 +23,4 @@ | ||
| $SCRIPT_DIR/compile-project.sh | ||
| # $SCRIPT_DIR/setup-s3.sh | ||
| $SCRIPT_DIR/deploy-lambda.sh | ||
| $SCRIPT_DIR/deploy-lambda.sh | ||
| $SCRIPT_DIR/setup-api-gateway.sh | ||
| $SCRIPT_DIR/clean-up.sh |
| #!/bin/bash -e | ||
| BUCKET_NAME="$APP_PREFIX-lambda-zip-bucket" | ||
@@ -5,0 +4,0 @@ |
6582
44.18%8
33.33%