Repository navigation
Closed
Labels
area/validatesam validate commandstage/waiting-for-releaseFix has been merged to develop and is waiting for a release
Description
Description:
A seemingly innocuous config with template.yaml and api.yaml gives an error on running sam validate.
The api.yaml seems to be a valid openAPI document as validated in a couple of sites (https://editor.swagger.io/ , https://apitools.dev/swagger-parser/online/).
The error only occurs if you add the CorsConfiguration to the HttpApi in the template. If you remove that section, the validation succeeds.
Steps to reproduce:
run sam validate in the directory with the following
template.yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: AltLinen
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
Properties:
AccessLogSettings:
DestinationArn: !GetAtt MyLogGroup.Arn
CorsConfiguration:
AllowMethods:
- POST
AllowHeaders:
- "Content-Type"
AllowOrigins:
- https://www.example.com
DefinitionBody:
"Fn::Transform":
Name: "AWS::Include"
Parameters:
Location: "./api.yaml"
MyLogGroup:
Type: AWS::Logs::LogGroup
MyHttpApiRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service: "apigateway.amazonaws.com"
Action:
- "sts:AssumeRole"
ShippingRatesLambda:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: appShipping.lambdaHandler
Runtime: nodejs12.x
Events:
APIPost:
Type: HttpApi
Properties:
Path: /shopify/shipping_rates
Method: POST
PayloadFormatVersion: "2.0"
Outputs:
ApiEndpoint:
Description: "HTTP API endpoint URL"
Value: !Sub "https://${MyHttpApi}.execute-api.${AWS::Region}.amazonaws.com"
and api.yaml
openapi: "3.0.1"
info:
title: "Alt Linen Backend"
version: "1.0.0"
paths:
/shopify/shipping_rates:
post:
responses:
default:
description: "Default response"
x-amazon-apigateway-importexport-version: "1.0"
Observed result:
2020-11-26 16:18:38,967 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
Template provided at '/Users/manu/developer/kindl/yamltest/template.yaml' was invalid SAM Template.
2020-11-26 16:18:46,181 | Sending Telemetry: {'metrics': [{'commandRun': {'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam validate', 'duration': 7212, 'exitReason': 'InvalidSamTemplateException', 'exitCode': 1, 'requestId': 'a0e88027-fe00-4231-9622-b936e502d9bd', 'installationId': '8ec6424d-7836-4a60-886a-e0ad452769d0', 'sessionId': '6758c9cb-cb59-4206-bc69-b51899bb089d', 'executionEnvironment': 'CLI', 'pyversion': '3.8.6', 'samcliVersion': '1.12.0'}}]}
2020-11-26 16:18:47,359 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
Error: [InvalidResourceException('MyHttpApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid OpenApi definition.")] ('MyHttpApi', "Unable to add Cors configuration because 'DefinitionBody' does not contain a valid OpenApi definition.")
Expected result:
Validation should succeed
OR, the correct validation error should be shown
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOS
sam --version: SAM CLI, version 1.12.0
Add --debug flag to command you are running
Metadata
Metadata
Assignees
Labels
area/validatesam validate commandstage/waiting-for-releaseFix has been merged to develop and is waiting for a release
Activity
NickLiffen commentedon Feb 3, 2021
I can also replicate this problem 👍 This is something that I am running into as well 👍 @manurana how did you overcome the problem?
manurana commentedon Feb 4, 2021
@NickLiffen : I just ignored it !
The deployment worked fine.
sriram-mv commentedon Apr 11, 2021
I just tried inlining the definition body without removing anything else and it just works.
sam validate worked when it was inlined like this, so did a deploy. This seems to do more with intrinsics not being resolved as well.
jfuss commentedon Jul 13, 2021
From Sriram's comment above this seems more like a SAM CLI issue given the deployment works but
sam validatedoesn't. Transferring to SAM CLI's Repo.mndeveci commentedon Feb 16, 2022
Released with SAM CLI v1.38.0
evin-murphy commentedon Oct 4, 2023
This issue is still occurring on SAM 1.72.0 when setting Auth ResourcePolicy and using
Fn::Transformon my OpenAPI file. I added a comment to #803 (comment)