- 追加された行はこの色です。
- 削除された行はこの色です。
#author("2019-03-19T19:08:19+00:00","","")
#mynavi(AWSメモ)
#setlinebreak(on);
* 目次 [#d56f3755]
#contents
- 関連
-- [[AWS CloudFormationメモ]]
-- [[独自ドメイン名で API Gateway または EC2にアクセスする]]
-- [[Lambda&API GatewayをCloudFormationで作成する]]
- 参考
-- https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html
#TODO
* 概要 [#l4882c74]
#html(<div style="padding-left: 10px;">)
カスタムドメインを使用するAPI Gateway のCloudFormationテンプレートのサンプル。
#html(</div>)
* ドメインの取得 [#d87a6d1a]
#html(<div style="padding-left: 10px;">)
任意のドメインレジストラ、もしくは Route53 でドメインを取得しておく。
#html(</div>)
* CloudFormation テンプレート [#q33a7ded]
#html(<div style="padding-left: 10px;">)
template.yml
#mycode2(){{
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
...
SampleCertificate:
Type: 'AWS::CertificateManager::Certificate'
Properties:
DomainName: example.mydomain.com
ValidationMethod: EMAIL
DomainName:
Type: 'AWS::ApiGateway::DomainName'
Properties:
CertificateArn: !Ref SampleCertificate
DomainName: example.mydomain.com
Mapping:
Type: 'AWS::ApiGateway::BasePathMapping'
Properties:
DomainName: !Ref DomainName
RestApiId: !Ref SampleApi
#BasePath: sample
SampleApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: 2.0
info:
title:
Ref: AWS::StackName
paths:
/:
get:
x-amazon-apigateway-integration:
httpMethod: POST # 統合リクエストで使用されるHTTP メソッド。Lambdaの場合はPOSTを指定
type: aws_proxy # Lambdaプロキシ統合
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${SampleFunction1.Arn}/invocations"
responses: {}
'/{id}':
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${SampleFunction1.Arn}/invocations"
responses: {}
# Lambda本体
SampleFunction1:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: SampleFunction1
Runtime: python3.6
Handler: index.handler
CodeUri: ./src
MemorySize: 128
Timeout: 60
Role: !GetAtt SampleFunction1Role.Arn
# Lambdaのロール
SampleFunction1Role:
Type: "AWS::IAM::Role"
Properties:
RoleName: SampleFunction1Role
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "lambda.amazonaws.com"
Action: "sts:AssumeRole"
Policies:
- PolicyName: "SampleFunction1Policy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
}}
#html(</div>)
* 補足 [#d804439f]
#html(<div style="padding-left: 10px;">)
証明書検証が済むまでは、スタックは CREATE_IN_PROGRESS 状態のままとなる。
以降のスタックオペレーションは、証明書検証 E メールの指示に応じて動作するか、CNAME レコードを DNS 設定に追加することにより、証明書リクエストを検証するまで延期される。
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-certificatemanager-certificate.html
関連: [[独自ドメイン名で API Gateway または EC2にアクセスする]] の 「ドメイン名の検証について」を参照。
#html(</div>)