Skip to content

Instantly share code, notes, and snippets.

View theawesomenayak's full-sized avatar

Siben Nayak theawesomenayak

View GitHub Profile
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
.withHeaders(headers);
try {
final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
String output = String
.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
return response.withStatusCode(200).withBody(output);
} catch (IOException e) {
return response.withBody("{}").withStatusCode(500);
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: HelloWorldFunction
Handler: helloworld.App::handleRequest
Runtime: java11
MemorySize: 512
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
private static final String NEWS_URL = "https://news.google.com/news/rss";
private static final HttpClient HTTP_CLIENT = HttpClient.newBuilder()
.version(Version.HTTP_2)
.followRedirects(HttpClient.Redirect.NORMAL)
.connectTimeout(Duration.ofSeconds(10))
.build();
private String getNewsFromGoogle()
throws IOException, InterruptedException, XMLStreamException {
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
public final class NewsItem {
private String title;
private String pubDate;
public String getTitle() {
return title;
}
try {
final String output = getNewsFromGoogle();
return response.withStatusCode(200).withBody(output);
} catch (final IOException | InterruptedException | XMLStreamException e) {
return response.withBody("{}").withStatusCode(500);
}
assertTrue(content.contains("\"title\""));
assertTrue(content.contains("\"date\""));
<groupId>petstore</groupId>
<artifactId>PetStore</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
package com.petstore.model;
public final class Pet {
private String id;
private String name;
private int age;
private String category;
// Getters and Setters
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb</artifactId>
<version>2.15.12</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>apache-client</artifactId>
<version>2.5.12</version>
</dependency>