Skip to content

Updated sample codes and also the ones on docs to follow the best practice for using Java String #436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc_source/java-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Handler implements RequestHandler<Map<String,String>, String>{
public String handleRequest(Map<String,String> event, Context context)
{
LambdaLogger logger = context.getLogger();
String response = new String("200 OK");
String response = "200 OK";
// log execution details
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
logger.log("CONTEXT: " + gson.toJson(context));
Expand Down Expand Up @@ -79,10 +79,10 @@ import [com\.amazonaws\.services\.lambda\.runtime\.LambdaLogger](https://github.
public class TestContext implements Context{
public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
...
public LambdaLogger getLogger(){
Expand Down
2 changes: 1 addition & 1 deletion doc_source/java-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Handler implements RequestHandler<Map<String,String>, String>{
public String handleRequest(Map<String,String> event, Context context)
{
LambdaLogger logger = context.getLogger();
String response = new String("200 OK");
String response = "200 OK";
// log execution details
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
logger.log("CONTEXT: " + gson.toJson(context));
Expand Down
2 changes: 1 addition & 1 deletion doc_source/java-logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Handler implements RequestHandler<Object, String>{
public String handleRequest(Object event, Context context)
{
LambdaLogger logger = context.getLogger();
String response = new String("SUCCESS");
String response = "SUCCESS";
// log execution details
logger.log("ENVIRONMENT VARIABLES: " + gson.toJson(System.getenv()));
logger.log("CONTEXT: " + gson.toJson(context));
Expand Down
12 changes: 6 additions & 6 deletions sample-apps/blank-java/src/test/java/example/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class TestContext implements Context{

public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
public String getLogStreamName(){
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
}
public String getFunctionName(){
return new String("my-function");
return "my-function";
}
public String getFunctionVersion(){
return new String("$LATEST");
return "$LATEST";
}
public String getInvokedFunctionArn(){
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
}
public CognitoIdentity getIdentity(){
return null;
Expand Down
12 changes: 6 additions & 6 deletions sample-apps/java-basic/src/test/java/example/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class TestContext implements Context{

public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
public String getLogStreamName(){
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
}
public String getFunctionName(){
return new String("my-function");
return "my-function";
}
public String getFunctionVersion(){
return new String("$LATEST");
return "$LATEST";
}
public String getInvokedFunctionArn(){
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
}
public CognitoIdentity getIdentity(){
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Handler implements RequestHandler<S3Event, String>{
@Override
public String handleRequest(S3Event event, Context context)
{
String response = new String("200 OK");
String response = "200 OK";
S3EventNotificationRecord record = event.getRecords().get(0);
String srcBucket = record.getS3().getBucket().getName();
// Object key may have spaces or unicode non-ASCII characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HandlerDynamoDB implements RequestHandler<DynamodbEvent, String>{
@Override
public String handleRequest(DynamodbEvent event, Context context)
{
String response = new String("200 OK");
String response = "200 OK";
for (DynamodbStreamRecord record : event.getRecords()){
logger.info(record.getEventID());
logger.info(record.getEventName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class HandlerKinesis implements RequestHandler<KinesisEvent, String>{
@Override
public String handleRequest(KinesisEvent event, Context context)
{
String response = new String("200 OK");
String response = "200 OK";
for(KinesisEventRecord record : event.getRecords()) {
logger.info(gson.toJson(record.getKinesis().getData()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class TestContext implements Context{

public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
public String getLogStreamName(){
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
}
public String getFunctionName(){
return new String("my-function");
return "my-function";
}
public String getFunctionVersion(){
return new String("$LATEST");
return "$LATEST";
}
public String getInvokedFunctionArn(){
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
}
public CognitoIdentity getIdentity(){
return null;
Expand Down
12 changes: 6 additions & 6 deletions sample-apps/java-events/src/test/java/example/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class TestContext implements Context{

public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
public String getLogStreamName(){
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
}
public String getFunctionName(){
return new String("my-function");
return "my-function";
}
public String getFunctionVersion(){
return new String("$LATEST");
return "$LATEST";
}
public String getInvokedFunctionArn(){
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
}
public CognitoIdentity getIdentity(){
return null;
Expand Down
12 changes: 6 additions & 6 deletions sample-apps/s3-java/src/test/java/example/TestContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ public class TestContext implements Context{

public TestContext() {}
public String getAwsRequestId(){
return new String("495b12a8-xmpl-4eca-8168-160484189f99");
return "495b12a8-xmpl-4eca-8168-160484189f99";
}
public String getLogGroupName(){
return new String("/aws/lambda/my-function");
return "/aws/lambda/my-function";
}
public String getLogStreamName(){
return new String("2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a");
return "2020/02/26/[$LATEST]704f8dxmpla04097b9134246b8438f1a";
}
public String getFunctionName(){
return new String("my-function");
return "my-function";
}
public String getFunctionVersion(){
return new String("$LATEST");
return "$LATEST";
}
public String getInvokedFunctionArn(){
return new String("arn:aws:lambda:us-east-2:123456789012:function:my-function");
return "arn:aws:lambda:us-east-2:123456789012:function:my-function";
}
public CognitoIdentity getIdentity(){
return null;
Expand Down