14
14
15
15
package org .demo .parameters ;
16
16
17
+ import static java .time .temporal .ChronoUnit .MILLIS ;
17
18
import static java .time .temporal .ChronoUnit .SECONDS ;
18
19
import static software .amazon .lambda .powertools .parameters .transform .Transformer .base64 ;
19
20
import static software .amazon .lambda .powertools .parameters .transform .Transformer .json ;
@@ -57,50 +58,33 @@ public class ParametersFunction implements RequestHandler<APIGatewayProxyRequest
57
58
.withTransformationManager (new TransformationManager ())
58
59
.build ();
59
60
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 );
70
61
71
62
@ Override
72
63
public APIGatewayProxyResponseEvent handleRequest (APIGatewayProxyRequestEvent input , Context context ) {
73
64
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
+
77
70
78
71
log .info ("allvalues (multiple):" );
79
72
allValues .forEach ((key , value ) -> log .info ("- {}={}\n " , key , value ));
80
73
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
-
86
74
Map <String , String > headers = new HashMap <>();
87
75
headers .put ("Content-Type" , "application/json" );
88
76
headers .put ("X-Custom-Header" , "application/json" );
89
77
90
78
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent ()
91
79
.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
+
104
88
}
105
89
106
90
private String getPageContents (String address ) throws IOException {
@@ -110,3 +94,4 @@ private String getPageContents(String address) throws IOException {
110
94
}
111
95
}
112
96
}
97
+
0 commit comments