Skip to content

Instantly share code, notes, and snippets.

@chintamanand
Last active April 19, 2023 18:22
Show Gist options
  • Save chintamanand/3be0859ed87d15fc1c5f27a391d1e579 to your computer and use it in GitHub Desktop.
Save chintamanand/3be0859ed87d15fc1c5f27a391d1e579 to your computer and use it in GitHub Desktop.
package com.javainuse.swaggertest;
public class PersonRequest {
private int id;
private String firstName;
private String lastName;
private String age;
private String address;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setId(int id) {
this.id = id;
}
public void setAge(String age) {
this.age = age;
}
public void setAddress(String address) {
this.address = address;
}
public int getId() {
return id;
}
public String getAge() {
return age;
}
public String getAddress() {
return address;
}
}
package com.javainuse.swaggertest;
public class PersonResponse {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javainuse</groupId>
<artifactId>springboot-swagger-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.1000</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.12.448</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/regions -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>regions</artifactId>
<version>2.20.48</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.11.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package com.javainuse.swaggertest;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
import com.amazonaws.services.dynamodbv2.model.AttributeValue;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestHandler;
import software.amazon.awssdk.regions.Region;
import java.util.HashMap;
import java.util.Map;
public class SavePersonHandler implements RequestHandler<PersonRequest, PersonResponse> {
private AmazonDynamoDB amazonDynamoDB;
private String DYNAMODB_TABLE_NAME = "Person";
private Region REGION = Region.US_WEST_2;
public PersonResponse handleRequest(PersonRequest personRequest, Context context) {
this.initDynamoDbClient();
persistData(personRequest);
PersonResponse personResponse = new PersonResponse();
personResponse.setMessage("Saved Successfully!!!");
return personResponse;
}
private void persistData(PersonRequest personRequest) {
Map<String, AttributeValue> attributesMap = new HashMap<String, AttributeValue>();
attributesMap.put("id", new AttributeValue(String.valueOf(personRequest.getId())));
attributesMap.put("firstName", new AttributeValue(personRequest.getFirstName()));
attributesMap.put("lastName", new AttributeValue(personRequest.getLastName()));
attributesMap.put("age", new AttributeValue(String.valueOf(personRequest.getAge())));
attributesMap.put("address", new AttributeValue(personRequest.getAddress()));
amazonDynamoDB.putItem(DYNAMODB_TABLE_NAME, attributesMap);
}
private void initDynamoDbClient() {
this.amazonDynamoDB = AmazonDynamoDBClientBuilder.standard()
.withRegion(REGION)
.build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment