-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
71773a6
commit eb29875
Showing
15 changed files
with
188 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,66 @@ | ||
#!/usr/bin/env bash | ||
|
||
awslocal s3 mb s3://testbucket | ||
echo "List of S3 buckets:" | ||
echo "-------------------------------" | ||
awslocal s3 ls | ||
|
||
awslocal sqs create-queue --queue-name test_queue | ||
echo "List of SQS Queues:" | ||
echo "-------------------------------" | ||
awslocal sqs list-queues | ||
# Navigate to the directory containing the JAR file | ||
cd /localstackTemp || exit 1 | ||
|
||
# Set variables | ||
JAR_FILE="aws-lambda-project-0.0.1-SNAPSHOT-aws.jar" | ||
FUNCTION_NAME="localstack-lambda-url-example" | ||
IAM_ROLE_ARN="arn:aws:iam::000000000000:role/lambda-role" | ||
|
||
# Function to display an error message and exit | ||
error_exit() { | ||
echo "Error: $1" >&2 | ||
exit 1 | ||
} | ||
|
||
# Check if the JAR file exists | ||
if [ ! -f "$JAR_FILE" ]; then | ||
error_exit "JAR file not found at $JAR_FILE" | ||
fi | ||
|
||
# Set environment variables (modify as needed) | ||
ENV_VARS='{"Variables": {"SPRING_DATASOURCE_URL":"jdbc:postgresql://postgresqldb:5432/appdb", "SPRING_DATASOURCE_USERNAME":"appuser", "SPRING_DATASOURCE_PASSWORD":"secret"}}' | ||
|
||
# Create Lambda function | ||
awslocal lambda create-function \ | ||
--function-name "$FUNCTION_NAME" \ | ||
--runtime java17 \ | ||
--timeout 10 \ | ||
--handler org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest \ | ||
--role "$IAM_ROLE_ARN" \ | ||
--zip-file "fileb://$JAR_FILE" \ | ||
--environment "$ENV_VARS" | ||
|
||
echo -e "Lambda function created successfully!\n" | ||
|
||
# Create function URL configuration and capture the output | ||
function_url_response=$(awslocal lambda create-function-url-config --function-name "$FUNCTION_NAME" --auth-type NONE) | ||
|
||
# Use jq to extract the FunctionUrl | ||
function_url=$(echo "$function_url_response" | grep -o '"FunctionUrl": "[^"]*' | cut -d'"' -f4) | ||
|
||
# Print the extracted FunctionUrl | ||
echo "FunctionUrl: $function_url" | ||
echo -e "Function URL configuration created!\n" | ||
|
||
# Wait until the function is active | ||
awslocal lambda wait function-active-v2 --function-name "$FUNCTION_NAME" | ||
echo -e "Lambda function is now active\n" | ||
|
||
# Invoke Lambda function or use curl | ||
#awslocal lambda invoke \ | ||
# --function-name "$FUNCTION_NAME" \ | ||
# --payload '{"body": "{\"name\": \"profile\"}" }' \ | ||
# output.txt | ||
# | ||
#echo -e "Lambda function invoked successfully\n" | ||
|
||
# Use curl to invoke Lambda function and capture the response | ||
response_from_curl=$(curl -X POST \ | ||
"$function_url" \ | ||
-H 'Content-Type: application/json' \ | ||
-d '{"name": "profile"}') | ||
|
||
# Print the response from curl | ||
echo "Response from curl: $response_from_curl" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
aws-lambda-project/src/main/java/com/learning/awslambda/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
aws-lambda-project/src/main/java/com/learning/awslambda/config/AWSLambdaConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.learning.awslambda.config; | ||
|
||
import com.learning.awslambda.model.request.ActorRequest; | ||
import com.learning.awslambda.model.response.ActorResponse; | ||
import com.learning.awslambda.services.ActorService; | ||
import java.util.function.Function; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
public class AWSLambdaConfig { | ||
|
||
@Bean | ||
Function<ActorRequest, ActorResponse> findActorByName(ActorService actorService) { | ||
return request -> actorService.findActorByName(request.name()); | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
aws-lambda-project/src/main/java/com/learning/awslambda/config/ApplicationProperties.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
aws-lambda-project/src/main/java/com/learning/awslambda/config/Initializer.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
aws-lambda-project/src/main/java/com/learning/awslambda/config/SwaggerConfig.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
aws-lambda-project/src/main/java/com/learning/awslambda/config/WebMvcConfig.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.