Amazon API Gateway
イシュー
参考
- 5分でわかるAmazon API Gateway – ナレコムAWSレシピ
- Amazon API Gateway を活用したゲームサーバー構築
- AWS Black Belt Tech シリーズ 2015 - Amazon API Gateway
- RESTに関して非常に丁寧に説明されている
- Api gatewayの話
- ...
- AWS LambdaとAPI Gatewayでサーバレスなシステム構築に踏み出してみる
- lambdaの軽い実装例
- https://www.slideshare.net/laitaka777/lambdaapi-gateway
- Amazon api gatewayで web apiをサーバーレスで構築しよう
- 認証、cognito
- AWSで始めるサーバレスな RESTful API システム
- Serverless AWS構成でセキュアなSPAを目指す
- サーバーレスSPA
- モデルとマッピングテンプレートの使用 - Amazon API Gateway
- AWS CLI コマンドを使用してエッジ最適化された API をセットアップする - Amazon API Gateway
FaaS (Fanction As a Service)
APIGateway x swagger
- 【初心者向け】SwaggerとAWS SAMを使ってWebAPIを簡単に作ってみた | DevelopersIO
- AWS CDKでSwaggerからAPI Gatewayを構築する - Qiita
- AWS CDK で API Gateway + Swaggerの環境を構築する | DevelopersIO
- class RestApi (construct) · AWS CDK
APIサンプル
{ "swagger": "2.0", "info": { "description": "Your first API with Amazon API Gateway. This is a sample API that integrates via HTTP with our demo Pet Store endpoints", "title": "PetStore" }, "schemes": [ "https" ], "paths": { "/": { "get": { "tags": [ "pets" ], "description": "PetStore HTML web page containing API usage information", "consumes": [ "application/json" ], "produces": [ "text/html" ], "responses": { "200": { "description": "Successful operation", "headers": { "Content-Type": { "type": "string", "description": "Media type of request" } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Content-Type": "'text/html'" }, "responseTemplates": { "text/html": "<html>\n <head>\n <style>\n body {\n color: #333;\n font-family: Sans-serif;\n max-width: 800px;\n margin: auto;\n }\n </style>\n </head>\n <body>\n <h1>Welcome to your Pet Store API</h1>\n <p>\n You have succesfully deployed your first API. You are seeing this HTML page because the <code>GET</code> method to the root resource of your API returns this content as a Mock integration.\n </p>\n <p>\n The Pet Store API contains the <code>/pets</code> and <code>/pets/{petId}</code> resources. By making a <a href=\"/$context.stage/pets/\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets</code> you can retrieve a list of Pets in your API. If you are looking for a specific pet, for example the pet with ID 1, you can make a <a href=\"/$context.stage/pets/1\" target=\"_blank\"><code>GET</code> request</a> to <code>/pets/1</code>.\n </p>\n <p>\n You can use a REST client such as <a href=\"https://www.getpostman.com/\" target=\"_blank\">Postman</a> to test the <code>POST</code> methods in your API to create a new pet. Use the sample body below to send the <code>POST</code> request:\n </p>\n <pre>\n{\n \"type\" : \"cat\",\n \"price\" : 123.11\n}\n </pre>\n </body>\n</html>" } } }, "passthroughBehavior": "when_no_match", "requestTemplates": { "application/json": "{\"statusCode\": 200}" }, "type": "mock" } } }, "/pets": { "get": { "tags": [ "pets" ], "summary": "List all pets", "produces": [ "application/json" ], "parameters": [ { "name": "type", "in": "query", "description": "The type of pet to retrieve", "required": false, "type": "string" }, { "name": "page", "in": "query", "description": "Page number of results to return.", "required": false, "type": "string" } ], "responses": { "200": { "description": "Successful operation", "schema": { "$ref": "#/definitions/Pets" }, "headers": { "Access-Control-Allow-Origin": { "type": "string", "description": "URI that may access the resource" } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Origin": "'*'" } } }, "requestParameters": { "integration.request.querystring.page": "method.request.querystring.page", "integration.request.querystring.type": "method.request.querystring.type" }, "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets", "passthroughBehavior": "when_no_match", "httpMethod": "GET", "type": "http" } }, "post": { "tags": [ "pets" ], "operationId": "CreatePet", "summary": "Create a pet", "consumes": [ "application/json" ], "produces": [ "application/json" ], "parameters": [ { "in": "body", "name": "NewPet", "required": true, "schema": { "$ref": "#/definitions/NewPet" } } ], "responses": { "200": { "description": "Successful operation", "schema": { "$ref": "#/definitions/NewPetResponse" }, "headers": { "Access-Control-Allow-Origin": { "type": "string", "description": "URI that may access the resource" } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Origin": "'*'" } } }, "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets", "passthroughBehavior": "when_no_match", "httpMethod": "POST", "type": "http" } }, "options": { "consumes": [ "application/json" ], "produces": [ "application/json" ], "responses": { "200": { "description": "Successful operation", "schema": { "$ref": "#/definitions/Empty" }, "headers": { "Access-Control-Allow-Origin": { "type": "string", "description": "URI that may access the resource" }, "Access-Control-Allow-Methods": { "type": "string", "description": "Method or methods allowed when accessing the resource" }, "Access-Control-Allow-Headers": { "type": "string", "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request." } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Methods": "'POST,GET,OPTIONS'", "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'", "method.response.header.Access-Control-Allow-Origin": "'*'" } } }, "passthroughBehavior": "when_no_match", "requestTemplates": { "application/json": "{\"statusCode\": 200}" }, "type": "mock" } } }, "/pets/{petId}": { "get": { "tags": [ "pets" ], "summary": "Info for a specific pet", "operationId": "GetPet", "produces": [ "application/json" ], "parameters": [ { "name": "petId", "in": "path", "description": "The id of the pet to retrieve", "required": true, "type": "string" } ], "responses": { "200": { "description": "Successful operation", "schema": { "$ref": "#/definitions/Pet" }, "headers": { "Access-Control-Allow-Origin": { "type": "string", "description": "URI that may access the resource" } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Origin": "'*'" } } }, "requestParameters": { "integration.request.path.petId": "method.request.path.petId" }, "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/pets/{petId}", "passthroughBehavior": "when_no_match", "httpMethod": "GET", "type": "http" } }, "options": { "consumes": [ "application/json" ], "produces": [ "application/json" ], "parameters": [ { "name": "petId", "in": "path", "description": "The id of the pet to retrieve", "required": true, "type": "string" } ], "responses": { "200": { "description": "Successful operation", "schema": { "$ref": "#/definitions/Empty" }, "headers": { "Access-Control-Allow-Origin": { "type": "string", "description": "URI that may access the resource" }, "Access-Control-Allow-Methods": { "type": "string", "description": "Method or methods allowed when accessing the resource" }, "Access-Control-Allow-Headers": { "type": "string", "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request." } } } }, "x-amazon-apigateway-integration": { "responses": { "default": { "statusCode": "200", "responseParameters": { "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'", "method.response.header.Access-Control-Allow-Origin": "'*'" } } }, "passthroughBehavior": "when_no_match", "requestTemplates": { "application/json": "{\"statusCode\": 200}" }, "type": "mock" } } } }, "definitions": { "Pets": { "type": "array", "items": { "$ref": "#/definitions/Pet" } }, "Empty": { "type": "object" }, "NewPetResponse": { "type": "object", "properties": { "pet": { "$ref": "#/definitions/Pet" }, "message": { "type": "string" } } }, "Pet": { "type": "object", "properties": { "id": { "type": "string" }, "type": { "type": "string" }, "price": { "type": "number" } } }, "NewPet": { "type": "object", "properties": { "type": { "$ref": "#/definitions/PetType" }, "price": { "type": "number" } } }, "PetType": { "type": "string", "enum": [ "dog", "cat", "fish", "bird", "gecko" ] } }, "x-amazon-apigateway-documentation": { "version": "v2.1", "createdDate": "2016-11-17T07:03:59Z", "documentationParts": [ { "location": { "type": "API" }, "properties": { "info": { "description": "Your first API with Amazon API Gateway. This is a sample API that integrates via HTTP with our demo Pet Store endpoints" } } }, { "location": { "type": "METHOD", "method": "GET" }, "properties": { "tags": [ "pets" ], "description": "PetStore HTML web page containing API usage information" } }, { "location": { "type": "METHOD", "path": "/pets/{petId}", "method": "GET" }, "properties": { "tags": [ "pets" ], "summary": "Info for a specific pet" } }, { "location": { "type": "METHOD", "path": "/pets", "method": "GET" }, "properties": { "tags": [ "pets" ], "summary": "List all pets" } }, { "location": { "type": "METHOD", "path": "/pets", "method": "POST" }, "properties": { "tags": [ "pets" ], "summary": "Create a pet" } }, { "location": { "type": "PATH_PARAMETER", "path": "/pets/{petId}", "method": "*", "name": "petId" }, "properties": { "description": "The id of the pet to retrieve" } }, { "location": { "type": "QUERY_PARAMETER", "path": "/pets", "method": "GET", "name": "page" }, "properties": { "description": "Page number of results to return." } }, { "location": { "type": "QUERY_PARAMETER", "path": "/pets", "method": "GET", "name": "type" }, "properties": { "description": "The type of pet to retrieve" } }, { "location": { "type": "REQUEST_BODY", "path": "/pets", "method": "POST" }, "properties": { "description": "Pet object that needs to be added to the store" } }, { "location": { "type": "RESPONSE", "method": "*", "statusCode": "200" }, "properties": { "description": "Successful operation" } }, { "location": { "type": "RESPONSE_HEADER", "method": "OPTIONS", "statusCode": "200", "name": "Access-Control-Allow-Headers" }, "properties": { "description": "Used in response to a preflight request to indicate which HTTP headers can be used when making the request." } }, { "location": { "type": "RESPONSE_HEADER", "method": "OPTIONS", "statusCode": "200", "name": "Access-Control-Allow-Methods" }, "properties": { "description": "Method or methods allowed when accessing the resource" } }, { "location": { "type": "RESPONSE_HEADER", "method": "*", "statusCode": "200", "name": "Access-Control-Allow-Origin" }, "properties": { "description": "URI that may access the resource" } }, { "location": { "type": "RESPONSE_HEADER", "method": "GET", "statusCode": "200", "name": "Content-Type" }, "properties": { "description": "Media type of request" } } ] } }
適当に作った、lambda と API Gateway でテストするとエラーになる
Thu Jul 05 01:46:37 UTC 2018 : Endpoint response body before transformations: "Hello from Lambda!" Thu Jul 05 01:46:37 UTC 2018 : Endpoint response headers: {X-Amz-Executed-Version=$LATEST, x-amzn-Remapped-Content-Length=0, Connection=keep-alive, x-amzn-RequestId=411dff2b-7ff5-11e8-96b3-3938705bbe0d, Content-Length=20, Date=Thu, 05 Jul 2018 01:46:37 GMT, X-Amzn-Trace-Id=root=1-5b3d787d-5d852a9159bcfa5d168076b0;sampled=0, Content-Type=application/json} Thu Jul 05 01:46:37 UTC 2018 : Execution failed due to configuration error: Malformed Lambda proxy response Thu Jul 05 01:46:37 UTC 2018 : Method completed with status: 502
- レスポンス自体は返っている。
参考
before
exports.handler = async (event) => { // TODO implement return 'Hello from Lambda!' };
*** after
exports.handler = (event, context, callback) => { var responseBody = { "key3": "value3", "key2": "value2", "key1": "value1" }; var response = { "statusCode": 200, "headers": { "my_header": "my_value" }, "body": JSON.stringify(responseBody), "isBase64Encoded": false }; callback(null, response); };
- node.jsでLambdaを実装した時のトラブル&解決策集 - Qiita
- I have been getting "Failed to write to 'index.js'. Please try again." whenever I try to update my lambda function code. I tried recreating the function again but to no avail - Forums
- chrome のバグとか、、。シークレットモードだとエラーが出ない。
次のエラー
Thu Jul 05 02:17:31 UTC 2018 : Sending request to https://lambda.ap-northeast-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:718994172625:function:helloworld/invocations Thu Jul 05 02:17:31 UTC 2018 : Execution failed due to configuration error: Invalid permissions on Lambda function Thu Jul 05 02:17:31 UTC 2018 : Method completed with status: 500
参考
ApiGatewayでのログの確認方法
ApiGatewayのログの確認方法
- API Gatewayのログ出力を有効化する - Qiita
Salesforce 外部データソース
イシュー
- Salesforceと外部のデータを連携する
参考
- 【Salesforce】Googleスプレッドシートを外部オブジェクトとして使ってみた|MURASAKI
- Salesforce <==> Google Spreadsheet連携
- Help | Training | Salesforce
- OData
- 外部データソースと外部オブジェクトを作成する 単元 | Salesforce Trailhead
郵便番号をPostgressへ格納する
参考
AWS Tips
イシュー
- AWSのTips
夜止めたい
参考
- CloudWatchとLambdaによるEC2の夜間停止 - Qiita
- EC2インスタンスをスケジュールで自動起動・自動停止させる(定時出社・定時退社)
- 起動・停止コード
- 定期的に EC2 インスタンスを停止・起動する仕組みの CloudFormation テンプレート | DevelopersIO
- Data Pipeline を使用した Amazon EC2 インスタンスの起動および停止
- amazon 公式
- できるだけシンプルな仕組みで簡単にEC2の自動起動・停止を実現したい! | DevelopersIO
- 1つのlambdaで起動と停止ができる
- Amazon CloudWatch の概念 - Amazon CloudWatch
EC2作成時にtimezoneを設定する
参考
- Amazon Linux起動時にCloudInitで設定するもの – サーバーワークスエンジニアブログ
- Linux インスタンスの時刻の設定 - Amazon Elastic Compute Cloud
- タイムゾーンの設定方法をメモ(RHEL6, RHEL7, Ubuntu編) | Siguniang's Blog
- redhat7の場合、timedatectl
HTTPS化したい
参考
- AWSを使ったHTTPS化 〜PART3〜 | Libra Studio エンジニアブログ
- AWSを使ったHTTPS化 〜PART2〜 | Libra Studio エンジニアブログ
- AWSを使ったHTTPS化 〜PART1〜 | Libra Studio エンジニアブログ
EC2に接続できなくなった時の対応方法
$ sudo mount /dev/xvdf1 /mnt/ebs
PC作業トラブル
イシュー
- PC作業でのトラブルシュート
PDFで印刷しようとすると .prnファイルになって印刷できない
- おちついて、印刷設定を確認し「ファイルへ出力」チェックボックスにチェックをつける
参考
- pdfを開いてその文書を印刷しようとするとpdfファイルが.prnになって保存のファイルが出て... |Adobe Community
Angular2 を速くしたい
イシュー
- Angular2アプリの起動が遅い
- なんとかしたい
参考
- Angular2 AoTコンパイルでTechFeedを高速化した話 – TechFeed – Medium
- AOTコンパイル
- Angular 2で作った最初のアプリの事後分析 : 使ってわかったAngular 2の長所と短所 | POSTD
- Angular2の失敗しない始め方〜「ng-japan 2016」セッションレポート〜 | HTML5Experts.jp
- Angular2アプリケーションのデプロイについて学ぶ - M12i.
- Angular 2で10万行書いた人にナマの声を聞く─奥野賢太郎×白石俊平 | HTML5Experts.jp
AOTコンパイル
Angular Ivy
AWS Troubleshooting
イシュー
EC2 のインスタンスステータスのチェックでエラー
- システムログを見ると SELinux policyでエラー
[ 5.089902] systemd[1]: Failed to load SELinux policy.
- よくある質問 - Amazon EC2 インスタンス | AWS
- SELinuxをCentOS 7 で有効化・無効化 (disabled, enforcing, permissive, setenforce) 停止の確認、設定 | urashita.com 浦下.com (ウラシタドットコム)
- Linux で Amazon EBS ボリュームを使用できるようにする - Amazon Elastic Compute Cloud
ボリュームを切り離して、別EC2で接続しようとしたが、そのままではマウントできない
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 10G 0 disk ├─xvda1 202:1 0 1M 0 part └─xvda2 202:2 0 10G 0 part / xvdf 202:80 0 30G 0 disk ├─xvdf1 202:81 0 1M 0 part └─xvdf2 202:82 0 30G 0 part $ sudo file -s /dev/xvdf /dev/xvdf: x86 boot sector; partition 1: ID=0xee, starthead 0, startsector 1, 62914559 sectors, extended partition table (last)\011, code offset 0x63
参考
- [AWS] XFSフォーマットのEBSを拡張して、認識させる方法 : 元うなぎ屋
- EC2 に ssh できない -> EBS 付け替えてレスキューした話 - dskst's diary
- AWSのLinuxインスタンスにログインできなくなった時の対処法 - Qiita
# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/xvda2 xfs 10473452 1002912 9470540 10% / devtmpfs devtmpfs 488224 0 488224 0% /dev tmpfs tmpfs 507480 0 507480 0% /dev/shm tmpfs tmpfs 507480 12984 494496 3% /run tmpfs tmpfs 507480 0 507480 0% /sys/fs/cgroup tmpfs tmpfs 101496 0 101496 0% /run/user/1000 tmpfs tmpfs 101496 0 101496 0% /run/user/0
# dmesg | tail [ 3300.518961] XFS (xvdf2): Filesystem has duplicate UUID 00a738da-7c2a-458c-83c0-2420aaed3b8a - can't mount
- 別EC2に起動できないEC2のボリュームをマウントして内容を確認
#mount -t xfs -o nouuid /dev/xvdf2 /mnt/data
- 結果:SELinuxの設定()の記載ミスがあった。修正して再起動したら起動した。
突然EC2に接続できなくなる
参考
- 接続できないインスタンスのトラブルシューティング - Amazon Elastic Compute Cloud
- ステータスチェックに失敗したインスタンスのトラブルシューティング - Amazon Elastic Compute Cloud
EBでEFS使用時のエラー
The following resource(s) failed to create: [MountTargetC, MountTargetA, MountTargetB].