Skip to content

Commit 753ecab

Browse files
author
Shivam Pandey
committed
readme with GET POST request examples
1 parent b5d5a0e commit 753ecab

File tree

1 file changed

+90
-2
lines changed

1 file changed

+90
-2
lines changed

README.md

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,106 @@ Gradle 4.8
88

99
Java 1.8
1010

11-
AWS Credentials stored at /.aws/credentials in the home directory
11+
AWS Credentials stored at /.aws/credentials in the home directory which can be created from the "My security credentials" section from the AWS dashboard.
12+
The credentials file has a form like
13+
14+
```
15+
[default]
16+
region=ap-south-1
17+
aws_access_key_id=##################
18+
aws_secret_access_key=##################
19+
```
20+
21+
The default is profile name which can be changed if we are using multiple profiles based on the region. `default` is used in the build.gradle at root of this project as
22+
23+
```
24+
aws {
25+
profileName = "default"
26+
region = 'ap-south-1'
27+
}
28+
```
29+
30+
### Set the AWS Lambda function region
31+
To set the region of lambda function, add the following block in the build.gradle file and this can be changed according to the region in use.
32+
33+
34+
```
35+
lambda {
36+
region = 'ap-south-1'
37+
}
38+
```
39+
40+
In this app, the main function is defined in the `MicronautFnAwsFunction` class and should be declared in the config as
41+
42+
```
43+
mainClassName = "micronaut.fn.aws.MicronautFnAwsFunction"
44+
```
45+
46+
It has a method named `executeMnAwsFunction` which is invoked when we hit the lambda function.
1247

1348
### Deployments
1449
To deploy the micronaut function on the AWS Lambda or testing locally, we have setup and tested this function with the following steps:
1550

1651
### Deploy the micronaut function to the AWS Lambda
1752

1853
####To deploy the fucntion on AWS directly from the console:
54+
55+
```
56+
micronaut-fn-aws git:(master) ✗ ./gradlew deploy
57+
58+
```
59+
60+
#### GET and POST requests (Only supported)
61+
### POST Request:
62+
To make a post request, add your request body in the `payload` as when you test from the console using `invoke` gradle task.
63+
64+
```
65+
payload = '{"customMessage": "This is custom message from user.", "customerId": "1"}'
66+
```
67+
The arguments can be customized based on the need in the method defined `executeMnAwsFunction` by changing its parameters.
68+
For an example:
69+
70+
The defined micronaut function is
71+
72+
```
73+
CustomResponse executeMnAwsFunction(CustomRequest request) {
74+
String customerId = request.customerId
75+
76+
CustomResponse customResponse = new CustomResponse()
77+
78+
if (customerId) {
79+
customResponse.customer = customerService.findCustomerById(customerId)
80+
}
81+
82+
customResponse.fromInterestService = interestService.methodName
83+
customResponse.fromMathService = mathematicsService.getEvenNumbers()
84+
85+
customResponse.message = request.customMessage ?: 'No message from console'
86+
87+
return customResponse
88+
}
89+
```
90+
91+
It accepts a request, a custom type, argument only.
92+
93+
### GET Request:
94+
To make a GET request, you do not need a `payload` and micronaut function should be no args.
95+
96+
#### Test the deployed function using the test events
97+
Create a test event using the request body:
98+
1999
```
20-
➜ micronaut-fn-aws git:(master) ✗ ./gradlew deploy
100+
{
101+
"customMessage": "This is custom message from user.",
102+
"customerId": "1"
103+
}
21104
```
22105

106+
and hit the test to see the results and summay details.
107+
108+
See the working:
109+
![](https://github.com/causecode/micronaut-fn-serverless/blob/master/assets/micronaut-aws-fn-demo.gif)
110+
23111
##### From Executable Jars
24112

25113
Use the following commands, where option in {} denotes the input to the lambda function created.

0 commit comments

Comments
 (0)