Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Flask~=1.0.2
boto3~=1.9, >=1.9.56
PyYAML~=5.1
cookiecutter~=1.6.0
aws-sam-translator==1.10.0
aws-sam-translator==1.13.1
docker~=4.0
dateparser~=0.7
python-dateutil~=2.6
Expand Down
11 changes: 9 additions & 2 deletions samcli/commands/validate/lib/sam_template_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,18 @@ def _replace_local_codeuri(self):
"""

all_resources = self.sam_template.get("Resources", {})
global_settings = self.sam_template.get("Globals", {})

for resource_type, properties in global_settings.items():

if resource_type == "Function":

SamTemplateValidator._update_to_s3_uri("CodeUri", properties)

for _, resource in all_resources.items():

resource_type = resource.get("Type")
resource_dict = resource.get("Properties")
resource_dict = resource.get("Properties", {})

if resource_type == "AWS::Serverless::Function":

Expand All @@ -90,7 +97,7 @@ def _replace_local_codeuri(self):
SamTemplateValidator._update_to_s3_uri("ContentUri", resource_dict)

if resource_type == "AWS::Serverless::Api":
if "DefinitionBody" not in resource_dict:
if "DefinitionUri" in resource_dict:
SamTemplateValidator._update_to_s3_uri("DefinitionUri", resource_dict)

@staticmethod
Expand Down
19 changes: 19 additions & 0 deletions tests/functional/commands/validate/lib/models/alexa_skill.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# File: sam.yml
# Version: 0.9

AWSTemplateFormatVersion: '2010-09-09'
Parameters: {}
Resources:
AlexaSkillFunc:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Description: Created by SAM
Events:
AlexaSkillEvent:
Type: AlexaSkill
Handler: index.handler
MemorySize: 1024
Runtime: nodejs4.3
Timeout: 3

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# File: sam.yml
# Version: 0.9

AWSTemplateFormatVersion: '2010-09-09'
Parameters: {}
Resources:
AlexaSkillFunc:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Description: Created by SAM
Events:
AlexaSkillEvent:
Type: AlexaSkill
Properties:
SkillId: amzn1.ask.skill.12345678-1234-1234-1234-123456789
Handler: index.handler
MemorySize: 1024
Runtime: nodejs4.3
Timeout: 3
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# "Kitchen Sink" test containing all supported policy templates. The idea is to know every one of them is
# transformable and fail on any changes in the policy template definition without updating the test
# Since this not about testing the transformation logic, we will keep the policy template parameter values as literal
# string

Resources:
KitchenSinkFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python2.7
Policies:

- SQSPollerPolicy:
QueueName: name

- LambdaInvokePolicy:
FunctionName: name

- CloudWatchPutMetricPolicy: {}

- EC2DescribePolicy: {}

- DynamoDBCrudPolicy:
TableName: name

- DynamoDBReadPolicy:
TableName: name

- SESSendBouncePolicy:
IdentityName: name

- ElasticsearchHttpPostPolicy:
DomainName: name

- S3ReadPolicy:
BucketName: name

- S3CrudPolicy:
BucketName: name

- AMIDescribePolicy: {}

- CloudFormationDescribeStacksPolicy: {}

- RekognitionNoDataAccessPolicy:
CollectionId: id

- RekognitionReadPolicy:
CollectionId: id

- RekognitionWriteOnlyAccessPolicy:
CollectionId: id

- SQSSendMessagePolicy:
QueueName: name

- SNSPublishMessagePolicy:
TopicName: name

- VPCAccessPolicy: {}

- DynamoDBStreamReadPolicy:
TableName: name
StreamName: name

- KinesisStreamReadPolicy:
StreamName: name

- SESCrudPolicy:
IdentityName: name

- SNSCrudPolicy:
TopicName: name

- KinesisCrudPolicy:
StreamName: name

- KMSDecryptPolicy:
KeyId: keyId

- PollyFullAccessPolicy:
LexiconName: name

- S3FullAccessPolicy:
BucketName: name

- CodePipelineLambdaExecutionPolicy: {}

- ServerlessRepoReadWriteAccessPolicy: {}

- EC2CopyImagePolicy:
ImageId: id

- CodePipelineReadOnlyPolicy:
PipelineName: pipeline

- CloudWatchDashboardPolicy: {}

- RekognitionFacesPolicy:
CollectionId: collection

- RekognitionLabelsPolicy: {}

- DynamoDBBackupFullAccessPolicy:
TableName: table

- DynamoDBRestoreFromBackupPolicy:
TableName: table

- ComprehendBasicAccessPolicy: {}

- AWSSecretsManagerRotationPolicy:
FunctionName: function

- MobileAnalyticsWriteOnlyAccessPolicy: {}

- PinpointEndpointAccessPolicy:
PinpointApplicationId: id

- RekognitionDetectOnlyPolicy: {}

- RekognitionFacesManagementPolicy:
CollectionId: collection

- EKSDescribePolicy: {}

- CostExplorerReadOnlyPolicy: {}

- OrganizationsListAccountsPolicy: {}

- DynamoDBReconfigurePolicy:
TableName: name

- SESBulkTemplatedCrudPolicy:
IdentityName: name

- SESEmailTemplateCrudPolicy: {}

- FilterLogEventsPolicy:
LogGroupName: name

- SSMParameterReadPolicy:
ParameterName: name

- StepFunctionsExecutionPolicy:
StateMachineName: name
22 changes: 22 additions & 0 deletions tests/functional/commands/validate/lib/models/api_cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Resources:
HtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs4.3
Events:
GetHtml:
Type: Api
Properties:
RestApiId: HtmlApi
Path: /
Method: get

HtmlApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
CacheClusterEnabled: true
CacheClusterSize: "1.6"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Parameters:
EndpointConfig:
Type: String

Globals:
Api:
# Overriding this property for Implicit API
EndpointConfiguration: {
"Ref": "EndpointConfig"
}

Resources:
ImplicitApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs4.3
Events:
GetHtml:
Type: Api
Properties:
Path: /
Method: get

ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
EndpointConfiguration: SomeValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Resources:
HtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs4.3
Events:
GetHtml:
Type: Api
Properties:
RestApiId: HtmlApi
Path: /
Method: get
RequestModel:
Model: User
Required: true

HtmlApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
Models:
User:
type: object
properties:
username:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Resources:
HtmlFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs4.3
Events:
GetHtml:
Type: Api
Properties:
RestApiId: HtmlApi
Path: /
Method: get
RequestModel:
Model: User
Required: true
Iam:
Type: Api
Properties:
RequestModel:
Model: User
Required: true
RestApiId:
Ref: HtmlApi
Method: get
Path: /iam
Auth:
Authorizer: AWS_IAM


HtmlApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
OpenApiVersion: '3.0.1'
Models:
User:
type: object
properties:
username:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Globals:
Api:
AccessLogSetting:
DestinationArn: "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910"
Format: "$context.requestId"

Resources:
ImplicitApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs4.3
Events:
GetHtml:
Type: Api
Properties:
Path: /
Method: get

ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json
Loading