1

JSON request sent from appSync to AWS lambda on mutation When we create a mutation request from appsynch to lambda resolver below JSON structure is passed as a event to lambda.

Could you please suggest best way to capture the event in lambda resolver?

{
"arguments": { "input" :
    {   
    "id"=null,
    "username": "MyName",
    "signIn": 0
    "active": true
    "typeId": 2
    "categoryTypeId": 3
    "isPossessable": true
    }   
 },
"identity": null,
"source": null,
"request": {
    "headers": {
        "x-forwarded-for": "103.123.78.9, 130.176.188.205",
        "sec-ch-ua-mobile": "?0",
        "dnt": "1",
        "cloudfront-viewer-country": "IN",
        "cloudfront-is-tablet-viewer": "false",
        "x-amzn-requestid": "5a2fb939-8748-40bc-b6eb-066d1b251b37",
        "via": "2.0 c5b17f7826bdac466315a86f2007a1cc.cloudfront.net (CloudFront)",
        "cloudfront-forwarded-proto": "https",
        "origin": "https://us-east-1.console.aws.amazon.com",
        "content-length": "106",
        "x-forwarded-proto": "https",
        "accept-language": "en-US,en;q=0.9",
        "host": "7z2ujz3rbjafvoonhy5jtx5dra.appsync-api.us-east-1.amazonaws.com",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
        "cloudfront-is-mobile-viewer": "false",
        "accept": "application/json, text/plain, /",
        "cloudfront-is-smarttv-viewer": "false",
        "accept-encoding": "gzip, deflate, br",
        "referer": "https://us-east-1.console.aws.amazon.com/",
        "x-api-key": "dg2-7nb73kk32be73hp4dmzvbyxz2ly",
        "content-type": "application/json",
        "sec-fetch-mode": "cors",
        "x-amzn-trace-id": "Root=1-62c27925-1abc0a56302093e2764b22e0",
        "x-amz-cf-id": "U3xaPlw75M4UNVoHvPXgu_5Wfdje6QlQTD6dIcyyA3rh4x8ypZSViA==",
        "sec-fetch-dest": "empty",
        "x-amz-user-agent": "AWS-Console-AppSync/",
        "sec-ch-ua-platform": "\"Windows\"",
        "cloudfront-is-desktop-viewer": "true",
        "sec-fetch-site": "cross-site",
        "sec-ch-ua": "\".Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"103\", \"Chromium\";v=\"103\"",
        "x-forwarded-port": "443"
    },
    "domainName": null
},
"prev": null,
"info": {
    "selectionSetList": [
    ],
    "selectionSetGraphQL": "{}",
    "fieldName": "createUser",
    "parentTypeName": "Mutation",
    "variables": {}
},
"stash": {}

}

Ajay
  • 176
  • 6
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 11 '22 at 08:27
  • When working with API Gateway, there is an event class for that `APIGatewayProxyRequestEvent`. I have not been able to find something similar for AppSync. You could use a `Map` or create your own class – Armando Prieto Feb 24 '23 at 18:06

1 Answers1

0

Maven dependency that worked for me:

     <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-core</artifactId>
        <version>1.2.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.amazonaws/aws-lambda-java-events -->
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-lambda-java-events</artifactId>
        <version>3.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.4.0</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.24</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>2.7.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>2.7.1</version>
    </dependency>
    <dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphql-spring-boot-starter</artifactId>
        <version>5.0.2</version>
    </dependency>
    <dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphql-spring-boot-starter</artifactId>
        <version>5.0.2</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-java-tools -->
    <dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphql-java-tools</artifactId>
        <version>5.2.4</version>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.4.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j2 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
        <version>2.7.1</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.9.0</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-spring-boot-starter -->
    <dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphql-spring-boot-starter</artifactId>
        <version>5.0.2</version>
    </dependency>
Ajay
  • 176
  • 6