• 프로필사진
    Home
  • Portfolio
  • github [#ffffff] Created with Sketch.
    Github
  • linkedin
    Linkedin
  • Setting
  • Posting
    • 분류 전체보기 (105)
      • Aws (96)
      • Backend (3)
      • Extension (1)
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • ApiGateway Post 에 특정한 문자 들어있으면 오류 발생시키기
        2024년 12월 27일
        • wngnl05
        • 작성자
        • 2024.12.27.오후03:00

        통합요청 매핑 템플릿 코드

        - id에 "admin"이 포함되어 있지 않으면 DynamoDB에 저장

        더보기
        #set($inputRoot = $input.path('$'))
        #if(!$input.params('id').contains('admin'))
          {
            "TableName": "serverless-user-table",
            "Item": {
                "id": {
                    "S": "$input.params('id')"
                },
                "age": {
                    "N": "$input.params('age')"
                },
                "company": {
                    "S": "$input.params('company')"
                }
            }
          }
        #end

        통합응답 매핑 템플릿 코드

        - id에 "admin"이 포함되어 있지 않으면 200 반환 포함되어 있으면 500 반환

        더보기
        #if(!$input.params('id').contains('admin'))
          #set($context.responseOverride.status = 200)
          {"msg": "Success insert data"}
        #else
          #set($context.responseOverride.status = 500)
          {"message": "Internal server error"}
        #end
        더보기

        요청

        { 
          "TableName": "serverless-user-table",
          "Key": {
            "id": { 
              "S": "$input.params('id')"
            }
          }
        }

        응답

        #set($inputRoot = $input.path('$'))
        {
          "id": "$inputRoot.Item.id.S",
          "age": "$inputRoot.Item.age.N"
          "company": "$inputRoot.Item.company.S"
        }

        []

        {msg: Success insert data} -status 200

        status 500

        {id:wngnl, age:19, company:hrdkorea} -status 200

        DynamoDB intergation found

        확인 후 Dynamo DB 데이터 삭제하기

        aws dynamodb scan --table-name serverless-user-table --query Items
        echo "-------------"
        apiId=$(aws apigateway get-rest-apis --query items[].id --output text)
        name="wngnl"
        curl -sS -w "\n - status code: %{http_code} \n" -X POST "https://$apiId.execute-api.ap-northeast-2.amazonaws.com/v1/user?id=$name&age=19&company=hrdkorea"
        echo "-------------"
        apiId=$(aws apigateway get-rest-apis --query items[].id --output text)
        curl -sS -w "\n - status code: %{http_code} \n" -o /dev/null -X POST "https://$apiId.execute-api.ap-northeast-2.amazonaws.com/v1/user?id=$name-admin&age=19&company=hrdkorea"
        echo "-------------"
        apiId=$(aws apigateway get-rest-apis --query items[].id --output text)
        curl -sS -w "\n - status code: %{http_code} \n" -X GET "https://$apiId.execute-api.ap-northeast-2.amazonaws.com/v1/user?id=$name"
        echo "-------------"
        apiId=$(aws apigateway get-rest-apis --query "items[?name=='serverless-api-gw'].id" --output text) && resourceId=$(aws apigateway get-resources --rest-api-id $apiId --query "items[?path=='/user'].id" --output text) && aws apigateway get-integration --rest-api-id $apiId --resource-id $resourceId --http-method GET --query "uri" --output text | grep -q 'dynamodb' && echo "DynamoDB integration found" || echo "DynamoDB integration not found"
        echo "-------------"
        aws dynamodb scan --table-name serverless-user-table --query Items

         

         

         

         

         

         

         

        저작자표시 비영리 변경금지 (새창열림)

        'Aws' 카테고리의 다른 글

        앤드포인트로 EC2 접속하는 방법  (0) 2024.12.27
        S3에 개체가 생성되면 SQS로 메시지 보내기  (0) 2024.12.27
        Config를 이용해서 Ec2-SecurityGroup REVOKE  (0) 2024.12.27
        Eks Nginx Ingress Controller 설치하기  (0) 2024.12.27
        Codecommit 에 Dockerfile을 위치하지 않고 Docker 배포하기  (0) 2024.12.27
        다음글
        다음 글이 없습니다.
        이전글
        이전 글이 없습니다.
        댓글
      조회된 결과가 없습니다.
      스킨 업데이트 안내
      현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
      ("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
      • 통합요청 매핑 템플릿 코드
      • 통합응답 매핑 템플릿 코드
      • 안녕하세요
      • 감사해요
      • 잘있어요

      티스토리툴바

      개인정보

      • 티스토리 홈
      • 포럼
      • 로그인

      단축키

      내 블로그

      내 블로그 - 관리자 홈 전환
      Q
      Q
      새 글 쓰기
      W
      W

      블로그 게시글

      글 수정 (권한 있는 경우)
      E
      E
      댓글 영역으로 이동
      C
      C

      모든 영역

      이 페이지의 URL 복사
      S
      S
      맨 위로 이동
      T
      T
      티스토리 홈 이동
      H
      H
      단축키 안내
      Shift + /
      ⇧ + /

      * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.