From 4d377d07bb41fc935fad0d178ea972427bb39355 Mon Sep 17 00:00:00 2001 From: Rehan Haider Date: Sat, 4 Jan 2025 11:53:59 +0000 Subject: [PATCH] updates --- content/aws/50001060-cdk-fn-s3-permission.md | 33 +++++++++++++++++- .../aws/50001060-01-lambda-response.png | Bin 0 -> 8525 bytes 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 content/images/aws/50001060-01-lambda-response.png diff --git a/content/aws/50001060-cdk-fn-s3-permission.md b/content/aws/50001060-cdk-fn-s3-permission.md index e17d004..0fc41c6 100644 --- a/content/aws/50001060-cdk-fn-s3-permission.md +++ b/content/aws/50001060-cdk-fn-s3-permission.md @@ -210,4 +210,35 @@ def handler(event, context): return {"statusCode": 200, "body": json.dumps(stored_data)} ``` -In the above code, we use the `boto3` library to interact with the S3 bucket. We first write the response from the API to a file in the bucket and then read the file and send the contents as a response. This method can be modified based on your exact use case. \ No newline at end of file +In the above code, we use the `boto3` library to interact with the S3 bucket. We first write the response from the API to a file in the bucket and then read the file and send the contents as a response. This method can be modified based on your exact use case. + +## Testing the Lambda function + +To test the Lambda function, we can use the `cdk` command to deploy the stack and then invoke the Lambda function. + +```bash +cdk deploy +``` + +This will deploy the stack and create the Lambda function. We can get the name of the Lambda function using AWS CLI's `list-functions` command: + +```bash +function_name=$(aws lambda list-functions --query "Functions[?contains(FunctionName, 'MyS3Function')].[FunctionName]" --output text) +``` + +Finally, invoke the Lambda function using the AWS CLI: + +```bash +aws lambda invoke \ + --function-name $function_name \ + --cli-binary-format raw-in-base64-out \ + --payload '{ "key": "value" }' \ + /dev/stdout | jq +``` + +![invoke-lambda-function]({static}/images/aws/50001060-01-lambda-response.png) + + +!!! note + The `jq` command is used to format the JSON output. If you don't have it installed, you can install it by running `brew install jq` on macOS or `apt-get install jq` on Linux. + diff --git a/content/images/aws/50001060-01-lambda-response.png b/content/images/aws/50001060-01-lambda-response.png new file mode 100644 index 0000000000000000000000000000000000000000..aa146f3156bc3b9fc25e79c316e15fdf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