public class MyJobLambda implements RequestHandler<Map<String, String>, Void> {
private static Logger LOGGER = LoggerFactory.getLogger(MyJobLambda.class);
@Override
public Void handleRequest(Map<String, String> event, Context context) {
LOGGER.debug("MyJob got value {} from input", event.get("key"));
return null;
}
但我得到了以下运行时异常:
An error occurred during JSON parsing: java.lang.RuntimeException
java.lang.RuntimeException: An error occurred during JSON parsing
Caused by: java.io.UncheckedIOException: com.amazonaws.lambda.thirdparty.com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('
"key": "value"
}
import os
import boto3
import json
#EVENT JSON PARSER (SYED)
def lambda_handler(event, context):
print('starting a new execution')
print('## ENVIRONMENT VARIABLES')
print(os.environ)
AMI = os.environ['AMI']
print('printing os variable AMI')
print(AMI)
print('#########################')
print('PRINTING EVENT')
print(event)
#return event
print('taking message payload from event')
#messagepayload = event['Records'][0]['Sns']['Message']
#the event[] gives a simple string
#the json.loads converts that string into a json/python dictionary that you can use
#[0] denotes first part of the array
messagepayload = json.loads(event['Records'][0]['Sns']['Message'])
print(messagepayload)
#key2 represents a key in the message payload json
#next we take value for the key named as key2
key2value = messagepayload['key2']
print(key2value)
return key2value
print('END OF EXECUTION')