Skip to content

Commit bb1aa76

Browse files
committed
Rejig parameters example to use the CRT client more heavily
1 parent 8d39247 commit bb1aa76

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import time
2+
from locust import HttpUser, task, between
3+
4+
class QuickstartUser(HttpUser):
5+
wait_time = between(1, 5)
6+
7+
@task
8+
def hello_world(self):
9+
self.client.get("/Prod/params/")

examples/powertools-examples-parameters/src/main/java/org/demo/parameters/ParametersFunction.java

+15-30
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package org.demo.parameters;
1616

17+
import static java.time.temporal.ChronoUnit.MILLIS;
1718
import static java.time.temporal.ChronoUnit.SECONDS;
1819
import static software.amazon.lambda.powertools.parameters.transform.Transformer.base64;
1920
import static software.amazon.lambda.powertools.parameters.transform.Transformer.json;
@@ -57,50 +58,33 @@ public class ParametersFunction implements RequestHandler<APIGatewayProxyRequest
5758
.withTransformationManager(new TransformationManager())
5859
.build();
5960

60-
String simpleValue = ssmProvider.withMaxAge(30, SECONDS).get("/powertools-java/sample/simplekey");
61-
String listValue = ssmProvider.withMaxAge(60, SECONDS).get("/powertools-java/sample/keylist");
62-
MyObject jsonObj = ssmProvider.withTransformation(json).get("/powertools-java/sample/keyjson", MyObject.class);
63-
Map<String, String> allValues = ssmProvider.getMultiple("/powertools-java/sample");
64-
String b64value = ssmProvider.withTransformation(base64).get("/powertools-java/sample/keybase64");
65-
66-
Map<String, String> secretJson =
67-
secretsProvider.withTransformation(json).get("/powertools-java/userpwd", Map.class);
68-
MyObject secretJsonObj = secretsProvider.withMaxAge(42, SECONDS).withTransformation(json)
69-
.get("/powertools-java/secretcode", MyObject.class);
7061

7162
@Override
7263
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
7364

74-
log.info("\n=============== SSM Parameter Store ===============");
75-
log.info("simplevalue={}, listvalue={}, b64value={}\n", simpleValue, listValue, b64value);
76-
log.info("jsonobj={}\n", jsonObj);
65+
String simpleValue = ssmProvider.withMaxAge(1, MILLIS).get("/powertools-java/sample/simplekey");
66+
String listValue = ssmProvider.withMaxAge(1, MILLIS).get("/powertools-java/sample/keylist");
67+
String jsonObj = ssmProvider.withMaxAge(1, MILLIS).get("/powertools-java/sample/keyjson");
68+
Map<String, String> allValues = ssmProvider.withMaxAge(1, MILLIS).getMultiple("/powertools-java/sample");
69+
7770

7871
log.info("allvalues (multiple):");
7972
allValues.forEach((key, value) -> log.info("- {}={}\n", key, value));
8073

81-
log.info("\n=============== Secrets Manager ===============");
82-
log.info("secretjson:");
83-
secretJson.forEach((key, value) -> log.info("- {}={}\n", key, value));
84-
log.info("secretjsonobj={}\n", secretJsonObj);
85-
8674
Map<String, String> headers = new HashMap<>();
8775
headers.put("Content-Type", "application/json");
8876
headers.put("X-Custom-Header", "application/json");
8977

9078
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
9179
.withHeaders(headers);
92-
try {
93-
final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
94-
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
95-
96-
return response
97-
.withStatusCode(200)
98-
.withBody(output);
99-
} catch (IOException e) {
100-
return response
101-
.withBody("{}")
102-
.withStatusCode(500);
103-
}
80+
81+
//final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
82+
String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", "bloop");
83+
84+
return response
85+
.withStatusCode(200)
86+
.withBody(output);
87+
10488
}
10589

10690
private String getPageContents(String address) throws IOException {
@@ -110,3 +94,4 @@ private String getPageContents(String address) throws IOException {
11094
}
11195
}
11296
}
97+

examples/powertools-examples-parameters/src/main/resources/log4j2.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Configuration packages="com.amazonaws.services.lambda.runtime.log4j2">
2+
<Configuration>
33
<Appenders>
44
<Console name="JsonAppender" target="SYSTEM_OUT">
5-
<LambdaJsonLayout compact="true" eventEol="true"/>
5+
<JsonTemplateLayout eventTemplateUri="classpath:LambdaJsonLayout.json" />
66
</Console>
77
</Appenders>
88
<Loggers>
9-
<Logger name="JsonLogger" level="INFO" additivity="false">
9+
<Logger name="com.example" level="debug" additivity="false">
1010
<AppenderRef ref="JsonAppender"/>
1111
</Logger>
1212
<Root level="info">

examples/powertools-examples-parameters/template.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ Resources:
1919
Handler: org.demo.parameters.ParametersFunction::handleRequest
2020
MemorySize: 512
2121
Tracing: Active
22+
Timeout: 60
2223
Environment:
2324
Variables:
2425
LOG_LEVEL: INFO
26+
#AWS_CODEGURU_PROFILER_ENABLED: TRUE
27+
#AWS_CODEGURU_PROFILER_GROUP_ARN: arn:aws:codeguru-profiler:eu-central-1:262576971904:profilingGroup/PowertoolsIdempProfile
28+
AWS_CODEGURU_PROFILER_GROUP_NAME: v3ProfileWithCrtFocus
29+
AWS_CODEGURU_PROFILER_TARGET_REGION: eu-central-1
30+
AWS_CODEGURU_PROFILER_HEAP_SUMMARY_ENABLED: TRUE
31+
JAVA_TOOL_OPTIONS: -javaagent:/opt/codeguru-profiler-java-agent-standalone.jar
32+
2533
Policies:
2634
- AWSSecretsManagerGetSecretValuePolicy:
2735
SecretArn: !Ref UserPwd

0 commit comments

Comments
 (0)