1
votes

I've followed this tutorial (https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html) to build a basic API.

Then, on the AWS API Gateway for lambda-pipeline-stack I added a custom domain (e.g. api.example.com) which points to a CloudFront distribution.

When I tried changing the template to use POST request instead of GET, I received an error:

This distribution is not configured to allow the HTTP request method that was used for this request.
The distribution supports only cachable requests.

However, when I go into my CloudFront distributions to try to enable POST, that distribution is not accessible. How can I enable POST for this type of API?

Here is my template for reference:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Shows time
Resources:
  TimeFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs10
      CodeUri: ./
      Events:
        MyTimeApi:
          Type: Api
          Properties:
            Path: /time
            Method: POST
1
What's the configuration of your Distribution, do you have the cloudformation template for that resource you can include? - pkarfs

1 Answers

0
votes

you need to allow POST on CloudFront because only GET, HEAD are allowed by default

Type: AWS::CloudFront::Distribution
Properties:
  DistributionConfig:
    ...
    HttpVersion: http2
    DefaultCacheBehavior:
     ...
      AllowedMethods: [DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT]

enter image description here