AppSync - Tutorial
Page content
Getting started
Set up
- Go to AppSync Page.
- Create API.
- Getting Started.
- Customize your API or import from Amazon DynamoDB -> Create with wizard
- Click Start
- Create model
- Model Name: Atlex00Model
- Configure model fields:- Name: uid, Type: ID, Required.
- Name: first_name: Type: String
- Name: last_name: Type: String
- Name: gender: Type: Int
- Name: age: Type: Int
- Name: email: Type: Email
 
- Name: 
- Configure model table (optional)- Table Name: Atlex00ModelTable
- Primary Key: uid, Sort key:first_name
 
- Create resources
- API configuration
- API name: atlex00AppSync
- Your API is almost ready… Updating the schema. Please do not refresh…
Use it
atlex00AppSync -> Queries
Check there is no item
Click the play button and select listAtlex00Models.
Result:
{
  "data": {
    "listAtlex00Models": {
      "items": []
    }
  }
}
Input an item
- Query variables
{
  "createatlex00modelinput": {
    "uid": "VbCqKXT5iqvT2Cv1ujThABuBt2Gn6I7x",
    "first_name": "Atlex",
    "last_name": "ID00",
    "gender": 0,
    "age": 29,
    "email": "mymail@example.com"
  }
}
- Click the play button and select createAtlex00Model.
{
  "data": {
    "createAtlex00Model": {
      "uid": "VbCqKXT5iqvT2Cv1ujThABuBt2Gn6I7x",
      "first_name": "Atlex",
      "last_name": "ID00",
      "gender": 0,
      "age": 29,
      "email": "mymail@example.com"
    }
  }
}
- Create with other id value
{
  "createatlex00modelinput": {
    "uid": "simpleuid",
    "first_name": "Atlex2",
    "last_name": "ID01",
    "gender": 1,
    "age": 30,
    "email": "mymail2@example.com"
  }
}
Click the play button and select createAtlex00Model.
{
  "data": {
    "createAtlex00Model": {
      "uid": "simpleuid",
      "first_name": "Atlex2",
      "last_name": "ID01",
      "gender": 1,
      "age": 30,
      "email": "mymail2@example.com"
    }
  }
}
- Try listAtlex00Models.
{
  "data": {
    "listAtlex00Models": {
      "items": [
        {
          "uid": "VbCqKXT5iqvT2Cv1ujThABuBt2Gn6I7x",
          "first_name": "Atlex",
          "last_name": "ID00",
          "gender": 0,
          "age": 29,
          "email": "mymail@example.com"
        },
        {
          "uid": "simpleuid",
          "first_name": "Atlex2",
          "last_name": "ID01",
          "gender": 1,
          "age": 30,
          "email": "mymail2@example.com"
        }
      ]
    }
  }
}
- In DynamoDB, Atlex00ModelTablewas created.
- There are two items, whose uids areVbCqKXT5iqvT2Cv1ujThABuBt2Gn6I7xandsimpleuidrespectively.
Draft: Send requests via the Internet
First try: failed
- AppSync -> My AppSync App -> Settings
- Get API URL,API IDandAPI Key
$ curl -H 'x-api-key: x-api-key:{{ My_API_Key }}' -d '{"query":"query {listMyModelTypes}"}' https://{{ My_API_URL_end_with_/graphql }} -vvv
*   Trying 65.9.83.9:443...
* TCP_NODELAY set
* Connected to xxxxxxxxxxxxxxxxxx.appsync-api.eu-central-1.amazonaws.com (65.9.83.9) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=*.appsync-api.eu-central-1.amazonaws.com
*  start date: Feb  5 00:00:00 2021 GMT
*  expire date: Mar  6 23:59:59 2022 GMT
*  subjectAltName: host "xxxxxxxxxxxxxxxxxxxxxxxxxx.appsync-api.eu-central-1.amazonaws.com" matched cert's "*.appsync-api.eu-central-1.amazonaws.com"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x564eba711800)
> POST /graphql HTTP/2
> Host: xxxxxxxxxxxxxxxxxxxxxxxxxx.appsync-api.eu-central-1.amazonaws.com
> user-agent: curl/7.68.0
> accept: */*
> x-api-key: x-api-key:{{ My_API_Key }}
> content-length: 36
> content-type: application/x-www-form-urlencoded
>
* We are completely uploaded and fine
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 401
< content-type: application/json;charset=UTF-8
< content-length: 129
< date: Sun, 28 Feb 2021 14:51:20 GMT
< x-amzn-requestid: xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx
< x-amzn-errortype: UnauthorizedException
< x-cache: Error from cloudfront
< via: 1.1 a06d82f018833bef3e7f2e9fd230e5ee.cloudfront.net (CloudFront)
< x-amz-cf-pop: AMS1-C1
< x-amz-cf-id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
<
{
  "errors" : [ {
    "errorType" : "UnauthorizedException",
    "message" : "You are not authorized to make this call."
  } ]
* Connection #0 to host xxxxxxxxxxxxxxxxxxxxxxxxxx.appsync-api.eu-central-1.amazonaws.com left intact
https://forums.aws.amazon.com/thread.jspa?threadID=293189 I can’t access the URL directly…
Not tested from here. I shift to use from AWS Amplify integration.
I guess, I should configure CloudFront. https://aws.amazon.com/de/blogs/mobile/use-a-custom-domain-with-aws-appsync-amazon-cloudfront-and-amazon-route-53/
Cloud Front
- Go to CloudFront.
- Create Distributuion
- Oreigin Settings- Origin Domain name: {{ API_URL_without_/graphql }}}
- Origin path: empty
- Origin ID: appsynd-origin-test
- Minimumm Origin SSL Protocol: TLSv1.2
- Origin Protocol Policy: HTTPS Only
- Alternate Domain Names (CNAMEs): yourdomain.com
 
- Origin Domain name: 
- Create distribution
- check domain name: xxxxxxxx.cloudfront.net
Configure Route 53. CNAME record. The value is the domain.