From 5bda9bce7b53fe6fc342a4c154b8480c49ce0b85 Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Fri, 9 Aug 2019 09:29:59 -0700 Subject: [PATCH 1/3] Update aws-sam-translator Dependency The `make pr` command set is passing, so pending integration tests. --- requirements/base.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/base.txt b/requirements/base.txt index 570a66fefd..fff8a7e1c5 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -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 From c740e420b505948711c5b6546377da9326f205bf Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Fri, 9 Aug 2019 14:30:54 -0700 Subject: [PATCH 2/3] SAM Validate Bug Fix and Many Tests We now test a number of models from the SAM repo in our functional tests. --- .../validate/lib/sam_template_validator.py | 12 +- .../validate/lib/models/alexa_skill.yaml | 19 ++ .../lib/models/alexa_skill_with_skill_id.yaml | 20 ++ .../lib/models/all_policy_templates.yaml | 148 ++++++++++++ .../validate/lib/models/api_cache.yaml | 22 ++ .../models/api_endpoint_configuration.yaml | 31 +++ .../lib/models/api_request_model.yaml | 28 +++ .../models/api_request_model_openapi_3.yaml | 42 ++++ .../models/api_with_access_log_setting.yaml | 25 ++ .../lib/models/api_with_auth_all_maximum.yaml | 105 ++++++++ .../api_with_auth_all_maximum_openapi_3.yaml | 106 ++++++++ .../lib/models/api_with_auth_all_minimum.yaml | 78 ++++++ .../api_with_auth_all_minimum_openapi.yaml | 81 +++++++ .../api_with_auth_and_conditions_all_max.yaml | 119 +++++++++ .../lib/models/api_with_auth_no_default.yaml | 75 ++++++ .../api_with_aws_iam_auth_overrides.yaml | 86 +++++++ .../models/api_with_binary_media_types.yaml | 32 +++ ...th_binary_media_types_definition_body.yaml | 29 +++ .../lib/models/api_with_canary_setting.yaml | 28 +++ .../validate/lib/models/api_with_cors.yaml | 80 +++++++ ..._with_cors_and_auth_no_preflight_auth.yaml | 48 ++++ ...api_with_cors_and_auth_preflight_auth.yaml | 47 ++++ ...cors_and_conditions_no_definitionbody.yaml | 55 +++++ ..._with_cors_and_only_credentials_false.yaml | 54 +++++ .../api_with_cors_and_only_headers.yaml | 70 ++++++ .../models/api_with_cors_and_only_maxage.yaml | 55 +++++ .../api_with_cors_and_only_methods.yaml | 19 ++ .../api_with_cors_and_only_origins.yaml | 68 ++++++ .../api_with_cors_no_definitionbody.yaml | 34 +++ .../lib/models/api_with_cors_openapi_3.yaml | 82 +++++++ .../models/api_with_default_aws_iam_auth.yaml | 47 ++++ .../models/api_with_gateway_responses.yaml | 28 +++ .../api_with_gateway_responses_all.yaml | 37 +++ ..._with_gateway_responses_all_openapi_3.yaml | 38 +++ .../api_with_gateway_responses_implicit.yaml | 27 +++ .../api_with_gateway_responses_minimal.yaml | 21 ++ ..._gateway_responses_string_status_code.yaml | 28 +++ .../models/api_with_method_aws_iam_auth.yaml | 39 +++ .../lib/models/api_with_method_settings.yaml | 36 +++ .../api_with_minimum_compression_size.yaml | 24 ++ .../lib/models/api_with_open_api_version.yaml | 22 ++ .../models/api_with_open_api_version_2.yaml | 22 ++ ..._with_openapi_definition_body_no_flag.yaml | 58 +++++ .../lib/models/api_with_resource_refs.yaml | 34 +++ ...pi_with_swagger_and_openapi_with_auth.yaml | 59 +++++ .../lib/models/api_with_xray_tracing.yaml | 21 ++ .../validate/lib/models/basic_function.yaml | 115 +++++++++ .../lib/models/basic_function_with_tags.yaml | 28 +++ .../validate/lib/models/basic_layer.yaml | 38 +++ .../lib/models/cloudwatch_logs_with_ref.yaml | 25 ++ .../validate/lib/models/cloudwatchevent.yaml | 26 ++ .../validate/lib/models/cloudwatchlog.yaml | 14 ++ .../validate/lib/models/depends_on.yaml | 48 ++++ .../validate/lib/models/explicit_api.yaml | 49 ++++ .../lib/models/explicit_api_openapi_3.yaml | 50 ++++ ...plicit_api_with_invalid_events_config.yaml | 51 ++++ .../lib/models/function_concurrency.yaml | 22 ++ .../lib/models/function_event_conditions.yaml | 93 +++++++ .../function_managed_inline_policy.yaml | 26 ++ .../lib/models/function_with_alias.yaml | 10 + ...function_with_alias_and_event_sources.yaml | 102 ++++++++ .../function_with_alias_intrinsics.yaml | 15 ++ .../lib/models/function_with_condition.yaml | 13 + ...stom_codedeploy_deployment_preference.yaml | 96 ++++++++ ...onal_codedeploy_deployment_preference.yaml | 19 ++ ...ction_with_deployment_and_custom_role.yaml | 40 ++++ ...ction_with_deployment_no_service_role.yaml | 40 ++++ .../function_with_deployment_preference.yaml | 10 + ..._deployment_preference_all_parameters.yaml | 44 ++++ ...ment_preference_multiple_combinations.yaml | 61 +++++ ...n_with_disabled_deployment_preference.yaml | 11 + .../lib/models/function_with_dlq.yaml | 21 ++ .../models/function_with_global_layers.yaml | 19 ++ .../lib/models/function_with_kmskeyarn.yaml | 34 +++ .../lib/models/function_with_layers.yaml | 42 ++++ .../lib/models/function_with_many_layers.yaml | 18 ++ .../function_with_permissions_boundary.yaml | 9 + .../function_with_policy_templates.yaml | 55 +++++ .../models/function_with_resource_refs.yaml | 52 ++++ ..._with_sns_event_source_all_parameters.yaml | 28 +++ .../global_handle_path_level_parameter.yaml | 64 +++++ .../validate/lib/models/globals_for_api.yaml | 58 +++++ .../lib/models/globals_for_function.yaml | 52 ++++ .../lib/models/globals_for_function_path.yaml | 51 ++++ .../lib/models/globals_for_simpletable.yaml | 8 + ...icit_and_explicit_api_with_conditions.yaml | 93 +++++++ .../validate/lib/models/implicit_api.yaml | 38 +++ ...icit_api_with_auth_and_conditions_max.yaml | 164 +++++++++++++ .../implicit_api_with_many_conditions.yaml | 226 ++++++++++++++++++ ...api_with_serverless_rest_api_resource.yaml | 45 ++++ .../lib/models/intrinsic_functions.yaml | 173 ++++++++++++++ .../validate/lib/models/iot_rule.yaml | 26 ++ .../lib/models/layers_all_properties.yaml | 38 +++ .../lib/models/layers_with_intrinsics.yaml | 48 ++++ ...api_with_serverless_rest_api_resource.yaml | 74 ++++++ .../commands/validate/lib/models/s3.yaml | 17 ++ .../validate/lib/models/s3_create_remove.yaml | 25 ++ ...ing_lambda_notification_configuration.yaml | 23 ++ ...ting_other_notification_configuration.yaml | 22 ++ .../validate/lib/models/s3_filter.yaml | 22 ++ .../s3_multiple_events_same_bucket.yaml | 28 +++ .../lib/models/s3_multiple_functions.yaml | 37 +++ .../lib/models/s3_with_condition.yaml | 23 ++ .../lib/models/s3_with_dependsOn.yaml | 21 ++ .../simple_table_ref_parameter_intrinsic.yaml | 22 ++ .../models/simple_table_with_extra_tags.yaml | 15 ++ .../models/simple_table_with_table_name.yaml | 22 ++ .../validate/lib/models/simpletable.yaml | 12 + .../lib/models/simpletable_with_sse.yaml | 6 + .../commands/validate/lib/models/sns.yaml | 16 ++ .../sns_existing_other_subscription.yaml | 20 ++ .../models/sns_topic_outside_template.yaml | 16 ++ .../commands/validate/lib/models/sqs.yaml | 14 ++ .../commands/validate/lib/models/streams.yaml | 28 +++ .../lib/models/unsupported_resources.yaml | 14 ++ .../lib/test_sam_template_validator.py | 134 ++++++++++- .../lib/test_sam_template_validator.py | 2 - 117 files changed, 5255 insertions(+), 5 deletions(-) create mode 100644 tests/functional/commands/validate/lib/models/alexa_skill.yaml create mode 100644 tests/functional/commands/validate/lib/models/alexa_skill_with_skill_id.yaml create mode 100644 tests/functional/commands/validate/lib/models/all_policy_templates.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_cache.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_endpoint_configuration.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_request_model.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_request_model_openapi_3.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_access_log_setting.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_all_maximum.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_all_maximum_openapi_3.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_all_minimum.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_all_minimum_openapi.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_and_conditions_all_max.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_auth_no_default.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_aws_iam_auth_overrides.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_binary_media_types.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_binary_media_types_definition_body.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_canary_setting.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_auth_no_preflight_auth.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_auth_preflight_auth.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_conditions_no_definitionbody.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_only_credentials_false.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_only_headers.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_only_maxage.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_only_methods.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_and_only_origins.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_no_definitionbody.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_cors_openapi_3.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_default_aws_iam_auth.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses_all.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses_all_openapi_3.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses_implicit.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses_minimal.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_gateway_responses_string_status_code.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_method_aws_iam_auth.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_method_settings.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_minimum_compression_size.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_open_api_version.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_open_api_version_2.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_openapi_definition_body_no_flag.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_resource_refs.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_swagger_and_openapi_with_auth.yaml create mode 100644 tests/functional/commands/validate/lib/models/api_with_xray_tracing.yaml create mode 100644 tests/functional/commands/validate/lib/models/basic_function.yaml create mode 100644 tests/functional/commands/validate/lib/models/basic_function_with_tags.yaml create mode 100644 tests/functional/commands/validate/lib/models/basic_layer.yaml create mode 100644 tests/functional/commands/validate/lib/models/cloudwatch_logs_with_ref.yaml create mode 100644 tests/functional/commands/validate/lib/models/cloudwatchevent.yaml create mode 100644 tests/functional/commands/validate/lib/models/cloudwatchlog.yaml create mode 100644 tests/functional/commands/validate/lib/models/depends_on.yaml create mode 100644 tests/functional/commands/validate/lib/models/explicit_api.yaml create mode 100644 tests/functional/commands/validate/lib/models/explicit_api_openapi_3.yaml create mode 100644 tests/functional/commands/validate/lib/models/explicit_api_with_invalid_events_config.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_concurrency.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_event_conditions.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_managed_inline_policy.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_alias.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_alias_and_event_sources.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_alias_intrinsics.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_condition.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_custom_codedeploy_deployment_preference.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_custom_conditional_codedeploy_deployment_preference.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_deployment_and_custom_role.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_deployment_no_service_role.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_deployment_preference.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_deployment_preference_all_parameters.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_deployment_preference_multiple_combinations.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_disabled_deployment_preference.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_dlq.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_global_layers.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_kmskeyarn.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_layers.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_many_layers.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_permissions_boundary.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_policy_templates.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_resource_refs.yaml create mode 100644 tests/functional/commands/validate/lib/models/function_with_sns_event_source_all_parameters.yaml create mode 100644 tests/functional/commands/validate/lib/models/global_handle_path_level_parameter.yaml create mode 100644 tests/functional/commands/validate/lib/models/globals_for_api.yaml create mode 100644 tests/functional/commands/validate/lib/models/globals_for_function.yaml create mode 100644 tests/functional/commands/validate/lib/models/globals_for_function_path.yaml create mode 100644 tests/functional/commands/validate/lib/models/globals_for_simpletable.yaml create mode 100644 tests/functional/commands/validate/lib/models/implicit_and_explicit_api_with_conditions.yaml create mode 100644 tests/functional/commands/validate/lib/models/implicit_api.yaml create mode 100644 tests/functional/commands/validate/lib/models/implicit_api_with_auth_and_conditions_max.yaml create mode 100644 tests/functional/commands/validate/lib/models/implicit_api_with_many_conditions.yaml create mode 100644 tests/functional/commands/validate/lib/models/implicit_api_with_serverless_rest_api_resource.yaml create mode 100644 tests/functional/commands/validate/lib/models/intrinsic_functions.yaml create mode 100644 tests/functional/commands/validate/lib/models/iot_rule.yaml create mode 100644 tests/functional/commands/validate/lib/models/layers_all_properties.yaml create mode 100644 tests/functional/commands/validate/lib/models/layers_with_intrinsics.yaml create mode 100644 tests/functional/commands/validate/lib/models/no_implicit_api_with_serverless_rest_api_resource.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_create_remove.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_existing_lambda_notification_configuration.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_existing_other_notification_configuration.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_filter.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_multiple_events_same_bucket.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_multiple_functions.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_with_condition.yaml create mode 100644 tests/functional/commands/validate/lib/models/s3_with_dependsOn.yaml create mode 100644 tests/functional/commands/validate/lib/models/simple_table_ref_parameter_intrinsic.yaml create mode 100644 tests/functional/commands/validate/lib/models/simple_table_with_extra_tags.yaml create mode 100644 tests/functional/commands/validate/lib/models/simple_table_with_table_name.yaml create mode 100644 tests/functional/commands/validate/lib/models/simpletable.yaml create mode 100644 tests/functional/commands/validate/lib/models/simpletable_with_sse.yaml create mode 100644 tests/functional/commands/validate/lib/models/sns.yaml create mode 100644 tests/functional/commands/validate/lib/models/sns_existing_other_subscription.yaml create mode 100644 tests/functional/commands/validate/lib/models/sns_topic_outside_template.yaml create mode 100644 tests/functional/commands/validate/lib/models/sqs.yaml create mode 100644 tests/functional/commands/validate/lib/models/streams.yaml create mode 100644 tests/functional/commands/validate/lib/models/unsupported_resources.yaml diff --git a/samcli/commands/validate/lib/sam_template_validator.py b/samcli/commands/validate/lib/sam_template_validator.py index 773fbf1c0a..a5b529b81d 100644 --- a/samcli/commands/validate/lib/sam_template_validator.py +++ b/samcli/commands/validate/lib/sam_template_validator.py @@ -63,6 +63,7 @@ def is_valid(self): template = sam_translator.translate(sam_template=self.sam_template, parameter_values={}) LOG.debug("Translated template is:\n%s", yaml_dump(template)) + print("Translated template is:\n%s", yaml_dump(template)) except InvalidDocumentException as e: raise InvalidSamDocumentException( functools.reduce(lambda message, error: message + ' ' + str(error), e.causes, str(e))) @@ -75,11 +76,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": @@ -90,7 +98,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 diff --git a/tests/functional/commands/validate/lib/models/alexa_skill.yaml b/tests/functional/commands/validate/lib/models/alexa_skill.yaml new file mode 100644 index 0000000000..f8d81b0a7a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/alexa_skill.yaml @@ -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 + diff --git a/tests/functional/commands/validate/lib/models/alexa_skill_with_skill_id.yaml b/tests/functional/commands/validate/lib/models/alexa_skill_with_skill_id.yaml new file mode 100644 index 0000000000..1714edb46e --- /dev/null +++ b/tests/functional/commands/validate/lib/models/alexa_skill_with_skill_id.yaml @@ -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 diff --git a/tests/functional/commands/validate/lib/models/all_policy_templates.yaml b/tests/functional/commands/validate/lib/models/all_policy_templates.yaml new file mode 100644 index 0000000000..2cca6996f8 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/all_policy_templates.yaml @@ -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 diff --git a/tests/functional/commands/validate/lib/models/api_cache.yaml b/tests/functional/commands/validate/lib/models/api_cache.yaml new file mode 100644 index 0000000000..2bd13be337 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_cache.yaml @@ -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" \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_endpoint_configuration.yaml b/tests/functional/commands/validate/lib/models/api_endpoint_configuration.yaml new file mode 100644 index 0000000000..899d2d6925 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_endpoint_configuration.yaml @@ -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 diff --git a/tests/functional/commands/validate/lib/models/api_request_model.yaml b/tests/functional/commands/validate/lib/models/api_request_model.yaml new file mode 100644 index 0000000000..b7b8ed768a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_request_model.yaml @@ -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 diff --git a/tests/functional/commands/validate/lib/models/api_request_model_openapi_3.yaml b/tests/functional/commands/validate/lib/models/api_request_model_openapi_3.yaml new file mode 100644 index 0000000000..0394ca5153 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_request_model_openapi_3.yaml @@ -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 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_access_log_setting.yaml b/tests/functional/commands/validate/lib/models/api_with_access_log_setting.yaml new file mode 100644 index 0000000000..f6c1dd920a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_access_log_setting.yaml @@ -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 diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum.yaml new file mode 100644 index 0000000000..89c94fdc7e --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum.yaml @@ -0,0 +1,105 @@ +Resources: + MyApi: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: arn:aws:1 + Identity: + Header: MyAuthorizationHeader + ValidationExpression: myauthvalidationexpression + + MyCognitoAuthMultipleUserPools: + UserPoolArn: + - arn:aws:2 + - arn:aws:3 + Identity: + Header: MyAuthorizationHeader2 + ValidationExpression: myauthvalidationexpression2 + + MyLambdaTokenAuth: + FunctionPayloadType: TOKEN + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Header: MyCustomAuthHeader + ValidationExpression: mycustomauthexpression + ReauthorizeEvery: 20 + + MyLambdaTokenAuthNoneFunctionInvokeRole: + FunctionArn: arn:aws + FunctionInvokeRole: NONE + Identity: + ReauthorizeEvery: 0 + + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Headers: + - Authorization1 + QueryStrings: + - Authorization2 + StageVariables: + - Authorization3 + Context: + - Authorization4 + ReauthorizeEvery: 0 + + MyFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithNoAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: / + Method: get + Auth: + Authorizer: NONE + WithCognitoMultipleUserPoolsAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: post + Auth: + Authorizer: MyCognitoAuthMultipleUserPools + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: get + Auth: + Authorizer: MyLambdaTokenAuth + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: patch + Auth: + Authorizer: MyLambdaTokenAuthNoneFunctionInvokeRole + WithLambdaRequestAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: delete + Auth: + Authorizer: MyLambdaRequestAuth + WithDefaultAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: put \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum_openapi_3.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum_openapi_3.yaml new file mode 100644 index 0000000000..8cab3cd48c --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_all_maximum_openapi_3.yaml @@ -0,0 +1,106 @@ +Resources: + MyApi: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + OpenApiVersion: '3.0.1' + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: arn:aws:1 + Identity: + Header: MyAuthorizationHeader + ValidationExpression: myauthvalidationexpression + + MyCognitoAuthMultipleUserPools: + UserPoolArn: + - arn:aws:2 + - arn:aws:3 + Identity: + Header: MyAuthorizationHeader2 + ValidationExpression: myauthvalidationexpression2 + + MyLambdaTokenAuth: + FunctionPayloadType: TOKEN + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Header: MyCustomAuthHeader + ValidationExpression: mycustomauthexpression + ReauthorizeEvery: 20 + + MyLambdaTokenAuthNoneFunctionInvokeRole: + FunctionArn: arn:aws + FunctionInvokeRole: NONE + Identity: + ReauthorizeEvery: 0 + + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Headers: + - Authorization1 + QueryStrings: + - Authorization2 + StageVariables: + - Authorization3 + Context: + - Authorization4 + ReauthorizeEvery: 0 + + MyFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithNoAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: / + Method: get + Auth: + Authorizer: NONE + WithCognitoMultipleUserPoolsAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: post + Auth: + Authorizer: MyCognitoAuthMultipleUserPools + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: get + Auth: + Authorizer: MyLambdaTokenAuth + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: patch + Auth: + Authorizer: MyLambdaTokenAuthNoneFunctionInvokeRole + WithLambdaRequestAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: delete + Auth: + Authorizer: MyLambdaRequestAuth + WithDefaultAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: put \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum.yaml new file mode 100644 index 0000000000..75568f21dd --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum.yaml @@ -0,0 +1,78 @@ +Resources: + MyApiWithCognitoAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + + MyApiWithLambdaTokenAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyLambdaTokenAuth + Authorizers: + MyLambdaTokenAuth: + FunctionArn: !GetAtt MyAuthFn.Arn + + MyApiWithLambdaRequestAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyLambdaRequestAuth + Authorizers: + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: !GetAtt MyAuthFn.Arn + Identity: + Headers: + - Authorization1 + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + MyFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + Cognito: + Type: Api + Properties: + RestApiId: !Ref MyApiWithCognitoAuth + Method: get + Path: /cognito + LambdaToken: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaTokenAuth + Method: get + Path: /lambda-token + LambdaRequest: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaRequestAuth + Method: get + Path: /lambda-request + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum_openapi.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum_openapi.yaml new file mode 100644 index 0000000000..1ce331e2b0 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_all_minimum_openapi.yaml @@ -0,0 +1,81 @@ +Globals: + Api: + OpenApiVersion: '3.0.1' +Resources: + MyApiWithCognitoAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + + MyApiWithLambdaTokenAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyLambdaTokenAuth + Authorizers: + MyLambdaTokenAuth: + FunctionArn: !GetAtt MyAuthFn.Arn + + MyApiWithLambdaRequestAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyLambdaRequestAuth + Authorizers: + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: !GetAtt MyAuthFn.Arn + Identity: + Headers: + - Authorization1 + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucketname/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + MyFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucketname/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + Cognito: + Type: Api + Properties: + RestApiId: !Ref MyApiWithCognitoAuth + Method: get + Path: /cognito + LambdaToken: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaTokenAuth + Method: get + Path: /lambda-token + LambdaRequest: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaRequestAuth + Method: get + Path: /lambda-request + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_and_conditions_all_max.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_and_conditions_all_max.yaml new file mode 100644 index 0000000000..f7c4a7db21 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_and_conditions_all_max.yaml @@ -0,0 +1,119 @@ +Conditions: + PathCondition: + Fn::Equals: + - true + - true +Resources: + MyApi: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: arn:aws:1 + Identity: + Header: MyAuthorizationHeader + ValidationExpression: myauthvalidationexpression + + MyCognitoAuthMultipleUserPools: + UserPoolArn: + - arn:aws:2 + - arn:aws:3 + Identity: + Header: MyAuthorizationHeader2 + ValidationExpression: myauthvalidationexpression2 + + MyLambdaTokenAuth: + FunctionPayloadType: TOKEN + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Header: MyCustomAuthHeader + ValidationExpression: mycustomauthexpression + ReauthorizeEvery: 20 + + MyLambdaTokenAuthNoneFunctionInvokeRole: + FunctionArn: arn:aws + FunctionInvokeRole: NONE + Identity: + ReauthorizeEvery: 0 + + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Headers: + - Authorization1 + QueryStrings: + - Authorization2 + StageVariables: + - Authorization3 + Context: + - Authorization4 + ReauthorizeEvery: 0 + + MyFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithNoAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: / + Method: get + Auth: + Authorizer: NONE + WithCognitoMultipleUserPoolsAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: post + Auth: + Authorizer: MyCognitoAuthMultipleUserPools + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: get + Auth: + Authorizer: MyLambdaTokenAuth + + MyFunctionWithConditional: + Type: AWS::Serverless::Function + Condition: PathCondition + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithLambdaTokenAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: patch + Auth: + Authorizer: MyLambdaTokenAuthNoneFunctionInvokeRole + WithLambdaRequestAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: delete + Auth: + Authorizer: MyLambdaRequestAuth + WithDefaultAuthorizer: + Type: Api + Properties: + RestApiId: !Ref MyApi + Path: /users + Method: put \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_auth_no_default.yaml b/tests/functional/commands/validate/lib/models/api_with_auth_no_default.yaml new file mode 100644 index 0000000000..5b033d79ac --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_auth_no_default.yaml @@ -0,0 +1,75 @@ +Resources: + MyApiWithCognitoAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + + MyApiWithLambdaTokenAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + Authorizers: + MyLambdaTokenAuth: + FunctionArn: !GetAtt MyAuthFn.Arn + + MyApiWithLambdaRequestAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + Authorizers: + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: !GetAtt MyAuthFn.Arn + Identity: + Headers: + - Authorization1 + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + MyFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + Cognito: + Type: Api + Properties: + RestApiId: !Ref MyApiWithCognitoAuth + Method: get + Path: /cognito + LambdaToken: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaTokenAuth + Method: get + Path: /lambda-token + LambdaRequest: + Type: Api + Properties: + RestApiId: !Ref MyApiWithLambdaRequestAuth + Method: get + Path: /lambda-request + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_aws_iam_auth_overrides.yaml b/tests/functional/commands/validate/lib/models/api_with_aws_iam_auth_overrides.yaml new file mode 100644 index 0000000000..f9cd47765a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_aws_iam_auth_overrides.yaml @@ -0,0 +1,86 @@ +Resources: + MyApiWithAwsIamAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: AWS_IAM + Authorizers: + MyCognitoAuth: + UserPoolArn: arn:aws:cognito-idp:xxxxxxxxx + InvokeRole: arn:aws:iam::123:role/AUTH_AWS_IAM + MyFunctionMyCognitoAuth: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + API1: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Method: get + Path: /MyFunctionMyCognitoAuth + Auth: + Authorizer: MyCognitoAuth + MyFunctionWithoutAuth: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + API2: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Method: get + Path: /MyFunctionWithoutAuth + MyFunctionNoneAuth: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + API3: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Method: get + Path: /MyFunctionNoneAuth + Auth: + Authorizer: NONE + MyFunctionDefaultInvokeRole: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + API3: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Method: get + Path: /MyFunctionDefaultInvokeRole + Auth: + Authorizer: AWS_IAM + InvokeRole: CALLER_CREDENTIALS + MyFunctionCustomInvokeRole: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + API3: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Method: get + Path: /MyFunctionCustomInvokeRole + Auth: + Authorizer: AWS_IAM + InvokeRole: arn:aws:iam::456::role/something-else diff --git a/tests/functional/commands/validate/lib/models/api_with_binary_media_types.yaml b/tests/functional/commands/validate/lib/models/api_with_binary_media_types.yaml new file mode 100644 index 0000000000..dfe4ed0f22 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_binary_media_types.yaml @@ -0,0 +1,32 @@ +Parameters: + BMT: + Type: String + Default: 'image~1jpg' +Globals: + Api: + BinaryMediaTypes: + - image~1gif + - {"Fn::Join": ["~1", ["image", "png"]]} + +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 + BinaryMediaTypes: + - application~1octet-stream + - !Ref BMT diff --git a/tests/functional/commands/validate/lib/models/api_with_binary_media_types_definition_body.yaml b/tests/functional/commands/validate/lib/models/api_with_binary_media_types_definition_body.yaml new file mode 100644 index 0000000000..6730419d4f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_binary_media_types_definition_body.yaml @@ -0,0 +1,29 @@ +Parameters: + BMT: + Type: String + Default: image~1jpeg +Globals: + Api: + BinaryMediaTypes: + - !Ref BMT + - image~1jpg + - {"Fn::Join": ["~1", ["image", "png"]]} + +Resources: + ExplicitApiManagedSwagger: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + BinaryMediaTypes: + - image~1gif + + ExplicitApiDefinitionBody: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + BinaryMediaTypes: + - application~1json + DefinitionBody: { + "paths": {}, + "swagger": "2.0", + } diff --git a/tests/functional/commands/validate/lib/models/api_with_canary_setting.yaml b/tests/functional/commands/validate/lib/models/api_with_canary_setting.yaml new file mode 100644 index 0000000000..d6fd057721 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_canary_setting.yaml @@ -0,0 +1,28 @@ +Globals: + Api: + CanarySetting: + PercentTraffic: 100 + StageVariablesOverrides: + sv1: "test" + sv2: "test2" + UseStageCache: false + +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 diff --git a/tests/functional/commands/validate/lib/models/api_with_cors.yaml b/tests/functional/commands/validate/lib/models/api_with_cors.yaml new file mode 100644 index 0000000000..6c6765dba8 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors.yaml @@ -0,0 +1,80 @@ +Globals: + Api: + Cors: { + "Fn::Join": [",", ["www.amazon.com", "www.google.com"]] + } + +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 + AnyApi: + Type: Api + Properties: + Path: /foo + Method: any + RestApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + Cors: + AllowMethods: "methods" + AllowHeaders: "headers" + AllowOrigin: "origins" + AllowCredentials: true diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_no_preflight_auth.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_no_preflight_auth.yaml new file mode 100644 index 0000000000..e33f486bad --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_no_preflight_auth.yaml @@ -0,0 +1,48 @@ +Globals: + Api: + Cors: "origins" + +Resources: + ApiFunction: + 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 + RestApiId: !Ref ServerlessApi + + PostHtml: + Type: Api + Properties: + Path: / + Method: post + RestApiId: !Ref ServerlessApi + + + ServerlessApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + Auth: + AddDefaultAuthorizerToCorsPreflight: False + DefaultAuthorizer: MyLambdaRequestAuth + Authorizers: + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: !GetAtt MyAuthFn.Arn + Identity: + Headers: + - Authorization1 + + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_preflight_auth.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_preflight_auth.yaml new file mode 100644 index 0000000000..45032209ce --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_auth_preflight_auth.yaml @@ -0,0 +1,47 @@ +Globals: + Api: + Cors: "origins" + +Resources: + ApiFunction: + 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 + RestApiId: !Ref ServerlessApi + + PostHtml: + Type: Api + Properties: + Path: / + Method: post + RestApiId: !Ref ServerlessApi + + + ServerlessApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: MyLambdaRequestAuth + Authorizers: + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: !GetAtt MyAuthFn.Arn + Identity: + Headers: + - Authorization1 + + MyAuthFn: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_conditions_no_definitionbody.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_conditions_no_definitionbody.yaml new file mode 100644 index 0000000000..67129b0e8d --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_conditions_no_definitionbody.yaml @@ -0,0 +1,55 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Conditions: + MyCondition: + Fn::Equals: + - true + - true +Globals: + Api: + # If we skip AllowMethods, then SAM will auto generate a list of methods scoped to each path + Cors: + AllowOrigin: "'www.example.com'" + +Resources: + ImplicitApiFunction2: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + Events: + DeleteHtml: + Type: Api + Properties: + RestApiId: !Ref ExplicitApi + Path: / + Method: delete + + ImplicitApiFunction: + Type: AWS::Serverless::Function + Condition: MyCondition + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + Events: + GetHtml: + Type: Api + Properties: + RestApiId: !Ref ExplicitApi + Path: / + Method: get + + PostHtml: + Type: Api + Properties: + RestApiId: !Ref ExplicitApi + Path: / + Method: post + + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_only_credentials_false.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_credentials_false.yaml new file mode 100644 index 0000000000..37f9e772d2 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_credentials_false.yaml @@ -0,0 +1,54 @@ +Globals: + Api: + Cors: + AllowCredentials: false + +Resources: + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + + + diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_only_headers.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_headers.yaml new file mode 100644 index 0000000000..6f1a9da497 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_headers.yaml @@ -0,0 +1,70 @@ +Globals: + Api: + Cors: + + # If we skip AllowMethods, then SAM will auto generate a list of methods scoped to each path + AllowHeaders: "headers" + +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 + + PostHtml: + Type: Api + Properties: + Path: / + Method: post + + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + + + diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_only_maxage.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_maxage.yaml new file mode 100644 index 0000000000..62ade857bd --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_maxage.yaml @@ -0,0 +1,55 @@ +Globals: + Api: + Cors: + # Minutes + MaxAge: 600 + +Resources: + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + + + diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_only_methods.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_methods.yaml new file mode 100644 index 0000000000..41b51515c9 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_methods.yaml @@ -0,0 +1,19 @@ +Globals: + Api: + Cors: + AllowMethods: "methods" + +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 + diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_and_only_origins.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_origins.yaml new file mode 100644 index 0000000000..2fab3d122d --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_and_only_origins.yaml @@ -0,0 +1,68 @@ +Globals: + Api: + # If we skip AllowMethods, then SAM will auto generate a list of methods scoped to each path + Cors: "origins" + +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 + + PostHtml: + Type: Api + Properties: + Path: / + Method: post + + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + + + diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_no_definitionbody.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_no_definitionbody.yaml new file mode 100644 index 0000000000..465422530f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_no_definitionbody.yaml @@ -0,0 +1,34 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Globals: + Api: + # If we skip AllowMethods, then SAM will auto generate a list of methods scoped to each path + Cors: "origins" + +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: + RestApiId: !Ref ExplicitApi + Path: / + Method: get + + PostHtml: + Type: Api + Properties: + RestApiId: !Ref ExplicitApi + Path: / + Method: post + + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_cors_openapi_3.yaml b/tests/functional/commands/validate/lib/models/api_with_cors_openapi_3.yaml new file mode 100644 index 0000000000..7465b9ee76 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_cors_openapi_3.yaml @@ -0,0 +1,82 @@ +Globals: + Api: + Cors: { + "Fn::Join": [",", ["www.amazon.com", "www.google.com"]] + } + OpenApiVersion: '3.0' + + +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 + AnyApi: + Type: Api + Properties: + Path: /foo + Method: any + RestApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.handler + Runtime: nodejs8.10 + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/add": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + } + }, + "responses": {} + } + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } + Cors: + AllowMethods: "methods" + AllowHeaders: "headers" + AllowOrigin: "origins" + AllowCredentials: true diff --git a/tests/functional/commands/validate/lib/models/api_with_default_aws_iam_auth.yaml b/tests/functional/commands/validate/lib/models/api_with_default_aws_iam_auth.yaml new file mode 100644 index 0000000000..1ab0f6600f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_default_aws_iam_auth.yaml @@ -0,0 +1,47 @@ +Resources: + MyApiWithAwsIamAuthAndDefaultInvokeRole: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: AWS_IAM + InvokeRole: CALLER_CREDENTIALS + MyApiWithAwsIamAuthAndCustomInvokeRole: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: AWS_IAM + InvokeRole: rn:aws:iam::123:role/AUTH_AWS_IAM + MyApiWithAwsIamAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + Auth: + DefaultAuthorizer: AWS_IAM + + MyFunctionWithAwsIamAuth: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + MyApiWithAwsIamAuth: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuth + Path: / + Method: get + MyApiWithAwsIamAuthAndCustomInvokeRole: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuthAndCustomInvokeRole + Path: / + Method: post + MyApiWithAwsIamAuthAndDefaultInvokeRole: + Type: Api + Properties: + RestApiId: !Ref MyApiWithAwsIamAuthAndDefaultInvokeRole + Path: / + Method: put diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses.yaml new file mode 100644 index 0000000000..1bb772aa93 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses.yaml @@ -0,0 +1,28 @@ +Resources: + Function: + 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 + RestApiId: !Ref ExplicitApi + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + GatewayResponses: + UNAUTHORIZED: + StatusCode: 401 + ResponseParameters: + Headers: + Access-Control-Expose-Headers: "'WWW-Authenticate'" + Access-Control-Allow-Origin: "'*'" + WWW-Authenticate: >- + 'Bearer realm="admin"' diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all.yaml new file mode 100644 index 0000000000..4a7bdfec86 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all.yaml @@ -0,0 +1,37 @@ +Resources: + Function: + 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 + RestApiId: !Ref ExplicitApi + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + GatewayResponses: + UNAUTHORIZED: + StatusCode: 401 + ResponseParameters: + Headers: + Access-Control-Expose-Headers: "'WWW-Authenticate'" + Access-Control-Allow-Origin: "'*'" + WWW-Authenticate: >- + 'Bearer realm="admin"' + Paths: + PathKey: "'path-value'" + QueryStrings: + QueryStringKey: "'query-string-value'" + QUOTA_EXCEEDED: + StatusCode: 429 + ResponseParameters: + Headers: + Retry-After: "'31536000'" diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all_openapi_3.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all_openapi_3.yaml new file mode 100644 index 0000000000..fe88f63d54 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_all_openapi_3.yaml @@ -0,0 +1,38 @@ +Resources: + Function: + 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 + RestApiId: !Ref ExplicitApi + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + OpenApiVersion: '3.0' + GatewayResponses: + UNAUTHORIZED: + StatusCode: 401 + ResponseParameters: + Headers: + Access-Control-Expose-Headers: "'WWW-Authenticate'" + Access-Control-Allow-Origin: "'*'" + WWW-Authenticate: >- + 'Bearer realm="admin"' + Paths: + PathKey: "'path-value'" + QueryStrings: + QueryStringKey: "'query-string-value'" + QUOTA_EXCEEDED: + StatusCode: 429 + ResponseParameters: + Headers: + Retry-After: "'31536000'" diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses_implicit.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_implicit.yaml new file mode 100644 index 0000000000..1bd7540688 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_implicit.yaml @@ -0,0 +1,27 @@ +Globals: + Api: + Name: "some api" + GatewayResponses: + UNAUTHORIZED: + StatusCode: 401 + ResponseParameters: + Headers: + Access-Control-Expose-Headers: "'WWW-Authenticate'" + Access-Control-Allow-Origin: "'*'" + WWW-Authenticate: >- + 'Bearer realm="admin"' + + +Resources: + Function: + 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 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses_minimal.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_minimal.yaml new file mode 100644 index 0000000000..e74053bd72 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_minimal.yaml @@ -0,0 +1,21 @@ +Resources: + Function: + 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 + RestApiId: !Ref ExplicitApi + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + GatewayResponses: + UNAUTHORIZED: {} diff --git a/tests/functional/commands/validate/lib/models/api_with_gateway_responses_string_status_code.yaml b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_string_status_code.yaml new file mode 100644 index 0000000000..22d807c7c3 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_gateway_responses_string_status_code.yaml @@ -0,0 +1,28 @@ +Resources: + Function: + 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 + RestApiId: !Ref ExplicitApi + + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + GatewayResponses: + UNAUTHORIZED: + StatusCode: '401' + ResponseParameters: + Headers: + Access-Control-Expose-Headers: "'WWW-Authenticate'" + Access-Control-Allow-Origin: "'*'" + WWW-Authenticate: >- + 'Bearer realm="admin"' diff --git a/tests/functional/commands/validate/lib/models/api_with_method_aws_iam_auth.yaml b/tests/functional/commands/validate/lib/models/api_with_method_aws_iam_auth.yaml new file mode 100644 index 0000000000..4becdb90a0 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_method_aws_iam_auth.yaml @@ -0,0 +1,39 @@ +Resources: + MyApiWithoutAuth: + Type: "AWS::Serverless::Api" + Properties: + StageName: Prod + + MyFunctionWithAwsIamAuth: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: index.handler + Runtime: nodejs8.10 + Events: + MyApiWithAwsIamAuth: + Type: Api + Properties: + RestApiId: !Ref MyApiWithoutAuth + Path: / + Method: get + Auth: + Authorizer: AWS_IAM + MyApiWithAwsIamAuthAndCustomInvokeRole: + Type: Api + Properties: + RestApiId: !Ref MyApiWithoutAuth + Path: / + Method: post + Auth: + Authorizer: AWS_IAM + InvokeRole: rn:aws:iam::123:role/AUTH_AWS_IAM + MyApiWithAwsIamAuthAndDefaultInvokeRole: + Type: Api + Properties: + RestApiId: !Ref MyApiWithoutAuth + Path: / + Method: put + Auth: + Authorizer: AWS_IAM + InvokeRole: CALLER_CREDENTIALS diff --git a/tests/functional/commands/validate/lib/models/api_with_method_settings.yaml b/tests/functional/commands/validate/lib/models/api_with_method_settings.yaml new file mode 100644 index 0000000000..efccaee35b --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_method_settings.yaml @@ -0,0 +1,36 @@ +Globals: + Api: + MethodSettings: [{ + # LOGGING!! + "LoggingLevel": "INFO", + + # METRICS!! + "MetricsEnabled": True, + + # Trace-level Logging + "DataTraceEnabled": True, + + # On all Paths & methods + "ResourcePath": "/*", + "HttpMethod": "*", + }] + +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 diff --git a/tests/functional/commands/validate/lib/models/api_with_minimum_compression_size.yaml b/tests/functional/commands/validate/lib/models/api_with_minimum_compression_size.yaml new file mode 100644 index 0000000000..79191d87ad --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_minimum_compression_size.yaml @@ -0,0 +1,24 @@ +Globals: + Api: + MinimumCompressionSize: 1024 + +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 + MinimumCompressionSize: 256 diff --git a/tests/functional/commands/validate/lib/models/api_with_open_api_version.yaml b/tests/functional/commands/validate/lib/models/api_with_open_api_version.yaml new file mode 100644 index 0000000000..dd91b26c9c --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_open_api_version.yaml @@ -0,0 +1,22 @@ +Globals: + Api: + OpenApiVersion: '3.0.1' + Cors: '*' + +Resources: + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod diff --git a/tests/functional/commands/validate/lib/models/api_with_open_api_version_2.yaml b/tests/functional/commands/validate/lib/models/api_with_open_api_version_2.yaml new file mode 100644 index 0000000000..b31fc72b93 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_open_api_version_2.yaml @@ -0,0 +1,22 @@ +Globals: + Api: + OpenApiVersion: '2.0' + Cors: '*' + +Resources: + ImplicitApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs8.10 + Events: + GetHtml: + Type: Api + Properties: + Path: / + Method: get + ExplicitApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod diff --git a/tests/functional/commands/validate/lib/models/api_with_openapi_definition_body_no_flag.yaml b/tests/functional/commands/validate/lib/models/api_with_openapi_definition_body_no_flag.yaml new file mode 100644 index 0000000000..9d0749660e --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_openapi_definition_body_no_flag.yaml @@ -0,0 +1,58 @@ +Globals: + Api: + Name: "some api" + CacheClusterEnabled: True + CacheClusterSize: "1.6" + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + Variables: + SomeVar: Value + +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: SomeStage + DefinitionBody: + openapi: 3.1.1 + info: + version: '1.0' + title: !Ref AWS::StackName + paths: + "/": + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations + responses: {} + + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_resource_refs.yaml b/tests/functional/commands/validate/lib/models/api_with_resource_refs.yaml new file mode 100644 index 0000000000..3381677ef2 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_resource_refs.yaml @@ -0,0 +1,34 @@ +# Test if resource references work for both Explicit API & Implicit API resources + +Resources: + MyApi: + Type: 'AWS::Serverless::Api' + Properties: + StageName: foo + DefinitionBody: + "this": "is" + "a": "swagger" + + MyFunction: + Type: "AWS::Serverless::Function" + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Events: + GetHtml: + Type: Api + Properties: + Path: /html + Method: GET + +Outputs: + ImplicitApiDeployment: + Value: !Ref ServerlessRestApi.Deployment + ImplicitApiStage: + Value: !Ref ServerlessRestApi.Stage + ExplicitApiDeployment: + Value: !Ref MyApi.Deployment + ExplicitApiStage: + Value: !Ref MyApi.Stage + diff --git a/tests/functional/commands/validate/lib/models/api_with_swagger_and_openapi_with_auth.yaml b/tests/functional/commands/validate/lib/models/api_with_swagger_and_openapi_with_auth.yaml new file mode 100644 index 0000000000..0e8ee19e74 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_swagger_and_openapi_with_auth.yaml @@ -0,0 +1,59 @@ +Globals: + Api: + Name: "some api" + CacheClusterEnabled: True + CacheClusterSize: "1.6" + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + Variables: + SomeVar: Value + +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: SomeStage + DefinitionBody: + openapi: 3.1.1 + swagger: 2.0 + info: + version: '1.0' + title: !Ref AWS::StackName + paths: + "/": + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations + responses: {} + + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/api_with_xray_tracing.yaml b/tests/functional/commands/validate/lib/models/api_with_xray_tracing.yaml new file mode 100644 index 0000000000..2752463db6 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/api_with_xray_tracing.yaml @@ -0,0 +1,21 @@ +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 + TracingEnabled: true diff --git a/tests/functional/commands/validate/lib/models/basic_function.yaml b/tests/functional/commands/validate/lib/models/basic_function.yaml new file mode 100644 index 0000000000..ae6ba50b4f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/basic_function.yaml @@ -0,0 +1,115 @@ +Parameters: + SomeParameter: + Type: String + Default: param + SomeOtherParameter: + Type: String + Default: otherparam +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + FunctionWithTracing: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Tracing: Active + + FunctionWithInlineCode: + Type: 'AWS::Serverless::Function' + Properties: + InlineCode: "hello world" + Handler: hello.handler + Runtime: python2.7 + Tracing: Active + + FunctionWithCodeUriObject: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: + Bucket: somebucket + Key: somekey + Version: "1" + Handler: hello.handler + Runtime: python2.7 + + CompleteFunction: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: MyAwesomeFunction + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Description: Starter Lambda Function + Timeout: 60 + VpcConfig: + SecurityGroupIds: + - sg-edcd9784 + SubnetIds: + - subnet-9d4a7b6c + - subnet-65ea5f08 + - {Ref: SomeParameter} + - {Ref: SomeOtherParameter} + Role: arn:aws:iam::012345678901:role/lambda_basic_execution + Environment: + Variables: + Name: Value + Name2: Value2 + FunctionWithPolicies: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: AmazonDynamoDBFullAccess + FunctionWithPolicyDocument: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: + Statement: + - Action: [ 'dynamodb:*' ] + Effect: Allow + Resource: '*' + FunctionWithRoleRef: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Role: + Fn::GetAtt: ["MyFunctionRole", "Arn"] + + MyFunctionRole: + # This is just some role. Actual role definition might be wrong + Type: "AWS::IAM::Role" + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - + Effect: "Allow" + Principal: + Service: + - "ec2.amazonaws.com" + Action: + - "sts:AssumeRole" + Path: "/" + Policies: + - + PolicyName: "root" + PolicyDocument: + Version: "2012-10-17" + Statement: + - + Effect: "Allow" + Action: "*" + Resource: "*" diff --git a/tests/functional/commands/validate/lib/models/basic_function_with_tags.yaml b/tests/functional/commands/validate/lib/models/basic_function_with_tags.yaml new file mode 100644 index 0000000000..aced4f2d37 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/basic_function_with_tags.yaml @@ -0,0 +1,28 @@ +# File: sam.yml +# Version: 0.9 + +AWSTemplateFormatVersion: '2010-09-09' +Parameters: + TagValueParam: + Type: String + Default: Val +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 + Tags: + TagKey1: TagValue1 + TagKey2: "" + TagKey3: + Ref: TagValueParam + TagKey4: "123" + diff --git a/tests/functional/commands/validate/lib/models/basic_layer.yaml b/tests/functional/commands/validate/lib/models/basic_layer.yaml new file mode 100644 index 0000000000..170af09b1a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/basic_layer.yaml @@ -0,0 +1,38 @@ +Conditions: + TestCondition: + Fn::Equals: + - beta + - beta + +Resources: + MinimalLayer: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + + LayerWithContentUriObject: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: + Bucket: somebucket + Key: somekey + Version: "v1" + RetentionPolicy: Delete + + CompleteLayer: + Type: 'AWS::Serverless::LayerVersion' + Properties: + LayerName: MyAwesomeLayer + ContentUri: s3://sam-demo-bucket/layer.zip + Description: Starter Lambda Layer + CompatibleRuntimes: + - python3.6 + - python2.7 + LicenseInfo: "License information" + RetentionPolicy: Retain + + LayerWithCondition: + Type: 'AWS::Serverless::LayerVersion' + Condition: TestCondition + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip diff --git a/tests/functional/commands/validate/lib/models/cloudwatch_logs_with_ref.yaml b/tests/functional/commands/validate/lib/models/cloudwatch_logs_with_ref.yaml new file mode 100644 index 0000000000..b818b66d8b --- /dev/null +++ b/tests/functional/commands/validate/lib/models/cloudwatch_logs_with_ref.yaml @@ -0,0 +1,25 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: Example CloudWatch Logs + Lambda +Parameters: + LogGroupName: + Type: String + Default: MyCWLogGroup + FilterPattern: + Type: String + Default: My filter pattern + +Resources: + TriggeredFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO + Handler: hello.handler + Runtime: python2.7 + Events: + CWLogEvent: + Type: CloudWatchLogs + Properties: + LogGroupName: !Ref LogGroupName + FilterPattern: !Ref FilterPattern + \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/cloudwatchevent.yaml b/tests/functional/commands/validate/lib/models/cloudwatchevent.yaml new file mode 100644 index 0000000000..28db31f84d --- /dev/null +++ b/tests/functional/commands/validate/lib/models/cloudwatchevent.yaml @@ -0,0 +1,26 @@ +Resources: + ScheduledFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO + Handler: hello.handler + Runtime: python2.7 + Events: + Schedule: + Type: Schedule + Properties: + Schedule: 'rate(1 minute)' + TriggeredFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO + Handler: hello.handler + Runtime: python2.7 + Events: + OnTerminate: + Type: CloudWatchEvent + Properties: + Pattern: + detail: + state: + - terminated diff --git a/tests/functional/commands/validate/lib/models/cloudwatchlog.yaml b/tests/functional/commands/validate/lib/models/cloudwatchlog.yaml new file mode 100644 index 0000000000..42b2f77151 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/cloudwatchlog.yaml @@ -0,0 +1,14 @@ +Resources: + TriggeredFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO + Handler: hello.handler + Runtime: python2.7 + Events: + CWLogEvent: + Type: CloudWatchLogs + Properties: + LogGroupName: MyCWLogGroup + FilterPattern: My filter pattern + diff --git a/tests/functional/commands/validate/lib/models/depends_on.yaml b/tests/functional/commands/validate/lib/models/depends_on.yaml new file mode 100644 index 0000000000..7ea5e5aad9 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/depends_on.yaml @@ -0,0 +1,48 @@ +# SAM template containing DependsOn property on resources. Output resources should +# also have this property set +Resources: + MyFunction: + Type: 'AWS::Serverless::Function' + DependsOn: ["MyExplicitApi", "MySamTable"] + Properties: + CodeUri: s3://sam-demo-bucket/code.zip + Handler: index.handler + Runtime: nodejs4.3 + Events: + MyApi: + Type: Api + Properties: + Path: / + Method: GET + RestApiId: MyExplicitApi + + MyExplicitApi: + Type: AWS::Serverless::Api + DependsOn: "MySamTable" + Properties: + DefinitionUri: s3://sam-translator-tests-dont-delete/swagger-http.json + StageName: dev + + + MySamTable: + Type: AWS::Serverless::SimpleTable + + + MyOtherTable: + # Test DependsOn property a non-SAM resource + Type: AWS::DynamoDB::Table + DependsOn: "MySamTable" + Properties: + + AttributeDefinitions: + - { AttributeName : id, AttributeType : S } + + KeySchema: + - { "AttributeName" : "id", "KeyType" : "HASH"} + + ProvisionedThroughput: + ReadCapacityUnits: 5 + WriteCapacityUnits: 5 + + StreamSpecification: + StreamViewType: "NEW_IMAGE" diff --git a/tests/functional/commands/validate/lib/models/explicit_api.yaml b/tests/functional/commands/validate/lib/models/explicit_api.yaml new file mode 100644 index 0000000000..0cef803f77 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/explicit_api.yaml @@ -0,0 +1,49 @@ +Parameters: + MyStageName: + Type: String + Default: Production + something: + Type: String + Default: something + +Resources: + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: + Bucket: sam-demo-bucket + Key: webpage.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Policies: AmazonDynamoDBReadOnlyAccess + Events: + GetHtml: + Type: Api + Properties: + RestApiId: + Ref: GetHtmlApi + Path: / + Method: get + + GetHtmlApi: + Type: AWS::Serverless::Api + Properties: + Name: MyGetApi + StageName: + Ref: MyStageName + DefinitionUri: + Bucket: sam-demo-bucket + Key: webpage_swagger.json + Variables: + EndpointUri: + Ref: something + EndpointUri2: http://example.com + + ApiWithInlineSwagger: + Type: AWS::Serverless::Api + Properties: + StageName: + Ref: MyStageName + DefinitionBody: + "this": "is" + "a": "inline swagger" diff --git a/tests/functional/commands/validate/lib/models/explicit_api_openapi_3.yaml b/tests/functional/commands/validate/lib/models/explicit_api_openapi_3.yaml new file mode 100644 index 0000000000..2a1bc936d1 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/explicit_api_openapi_3.yaml @@ -0,0 +1,50 @@ +Parameters: + MyStageName: + Type: String + Default: Production + something: + Type: String + Default: something + +Resources: + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: + Bucket: sam-demo-bucket + Key: webpage.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Policies: AmazonDynamoDBReadOnlyAccess + Events: + GetHtml: + Type: Api + Properties: + RestApiId: + Ref: GetHtmlApi + Path: / + Method: get + + GetHtmlApi: + Type: AWS::Serverless::Api + Properties: + Name: MyGetApi + StageName: + Ref: MyStageName + DefinitionUri: + Bucket: sam-demo-bucket + Key: webpage_swagger.json + Variables: + EndpointUri: + Ref: something + EndpointUri2: http://example.com + + ApiWithInlineSwagger: + Type: AWS::Serverless::Api + Properties: + StageName: + Ref: MyStageName + OpenApiVersion: '3.0' + DefinitionBody: + "this": "is" + "a": "inline swagger" diff --git a/tests/functional/commands/validate/lib/models/explicit_api_with_invalid_events_config.yaml b/tests/functional/commands/validate/lib/models/explicit_api_with_invalid_events_config.yaml new file mode 100644 index 0000000000..9f0e4285b5 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/explicit_api_with_invalid_events_config.yaml @@ -0,0 +1,51 @@ +# This is specifically testing a invalid SAM template, that is currently accepted by SAM, and some customers rely on this behavior. +# We will eventually change the behavior to error on this invalid template, but until then, this test will guard against +# inadvertently changing this behavior. + +# When a Function's Event contains a path that is "not" in the Swagger, the behavior would be just add Lambda::Permissions +# and leaving the Swagger unmodified. + +Resources: + MyFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/todo_list.zip + Handler: index.restapi + Runtime: nodejs4.3 + Events: + AddApi: + Type: Api + Properties: + # /add is NOT present in the Swagger. + Path: /add + Method: post + RestApiId: ApiWithInlineSwagger + + + ApiWithInlineSwagger: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + DefinitionBody: { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/foo": { + "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + }, + "responses": {} + } + } + }, + "swagger": "2.0" + } diff --git a/tests/functional/commands/validate/lib/models/function_concurrency.yaml b/tests/functional/commands/validate/lib/models/function_concurrency.yaml new file mode 100644 index 0000000000..ff39277a4e --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_concurrency.yaml @@ -0,0 +1,22 @@ +Parameters: + Concurrency: + Type: Number + +Resources: + ConcurrentFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + ReservedConcurrentExecutions: 100 + + AnotherFunction: + Type: "AWS::Serverless::Function" + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + ReservedConcurrentExecutions: { + "Ref": "Concurrency" + } \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/function_event_conditions.yaml b/tests/functional/commands/validate/lib/models/function_event_conditions.yaml new file mode 100644 index 0000000000..3dd9bad2a4 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_event_conditions.yaml @@ -0,0 +1,93 @@ +Conditions: + MyCondition: + Fn::Equals: + - true + - true + +Resources: + +# S3 Event without condition, using same bucket + FunctionOne: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + +# All Event Types + MyAwesomeFunction: + Type: 'AWS::Serverless::Function' + Condition: MyCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + AutoPublishAlias: Live + + Events: + CWSchedule: + Type: Schedule + Properties: + Schedule: 'rate(1 minute)' + + CWEvent: + Type: CloudWatchEvent + Properties: + Pattern: + detail: + state: + - terminated + + CWLog: + Type: CloudWatchLogs + Properties: + LogGroupName: MyLogGroup + FilterPattern: My pattern + + IoTRule: + Type: IoTRule + Properties: + Sql: SELECT * FROM 'topic/test' + AwsIotSqlVersion: beta + + S3Trigger: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + NotificationTopic: + Type: SNS + Properties: + Topic: + Ref: Notifications + + KinesisStream: + Type: Kinesis + Properties: + Stream: arn:aws:kinesis:us-west-2:012345678901:stream/my-stream + BatchSize: 100 + StartingPosition: TRIM_HORIZON + + DDBStream: + Type: DynamoDB + Properties: + Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291 + BatchSize: 200 + StartingPosition: LATEST + + Notifications: + Condition: MyCondition + Type: AWS::SNS::Topic + + Images: + Type: AWS::S3::Bucket diff --git a/tests/functional/commands/validate/lib/models/function_managed_inline_policy.yaml b/tests/functional/commands/validate/lib/models/function_managed_inline_policy.yaml new file mode 100644 index 0000000000..538d5f3c69 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_managed_inline_policy.yaml @@ -0,0 +1,26 @@ +Parameters: + SomeManagedPolicyArn: + Type: String + Default: arn:aws:iam::aws:policy/OtherPolicy +Resources: + Function: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: + - Statement: + - Action: [ 'dynamodb:*' ] + Effect: Allow + Resource: '*' + - AmazonDynamoDBFullAccess + # Duplicate Policies should get de-duped + - AmazonDynamoDBFullAccess + - AWSLambdaBasicExecutionRole + + - AWSLambdaRole + + # Intrinsic functions & custom policy ARNs must be supported + - {"Ref": "SomeManagedPolicyArn"} + - arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy diff --git a/tests/functional/commands/validate/lib/models/function_with_alias.yaml b/tests/functional/commands/validate/lib/models/function_with_alias.yaml new file mode 100644 index 0000000000..4a2defb45e --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_alias.yaml @@ -0,0 +1,10 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + VersionDescription: sam-testing + diff --git a/tests/functional/commands/validate/lib/models/function_with_alias_and_event_sources.yaml b/tests/functional/commands/validate/lib/models/function_with_alias_and_event_sources.yaml new file mode 100644 index 0000000000..0d436671c7 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_alias_and_event_sources.yaml @@ -0,0 +1,102 @@ +# Testing Alias Invoke with ALL event sources supported by Lambda +# We are looking to check if the event sources and their associated Lambda::Permission resources are +# connect to the Alias and *not* the function +Parameters: + MyStageName: + Type: String + Default: beta +Resources: + MyAwesomeFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + AutoPublishAlias: Live + + Events: + CWSchedule: + Type: Schedule + Properties: + Schedule: 'rate(1 minute)' + + CWEvent: + Type: CloudWatchEvent + Properties: + Pattern: + detail: + state: + - terminated + + CWLog: + Type: CloudWatchLogs + Properties: + LogGroupName: MyLogGroup + FilterPattern: My pattern + + ExplicitApi: + Type: Api + Properties: + RestApiId: + Ref: GetHtmlApi + Path: / + Method: get + + ImplicitApi: + Type: Api + Properties: + Path: /add + Method: post + + IoTRule: + Type: IoTRule + Properties: + Sql: SELECT * FROM 'topic/test' + AwsIotSqlVersion: beta + + S3Trigger: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + NotificationTopic: + Type: SNS + Properties: + Topic: + Ref: Notifications + + KinesisStream: + Type: Kinesis + Properties: + Stream: arn:aws:kinesis:us-west-2:012345678901:stream/my-stream + BatchSize: 100 + StartingPosition: TRIM_HORIZON + + DDBStream: + Type: DynamoDB + Properties: + Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291 + BatchSize: 200 + StartingPosition: LATEST + + Notifications: + Type: AWS::SNS::Topic + + Images: + Type: AWS::S3::Bucket + + GetHtmlApi: + Type: AWS::Serverless::Api + Properties: + Name: MyGetApi + StageName: + Ref: MyStageName + DefinitionUri: + Bucket: sam-demo-bucket + Key: webpage_swagger.json + Variables: + LambdaFunction: + Ref: "MyAwesomeFunction" diff --git a/tests/functional/commands/validate/lib/models/function_with_alias_intrinsics.yaml b/tests/functional/commands/validate/lib/models/function_with_alias_intrinsics.yaml new file mode 100644 index 0000000000..99327286bf --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_alias_intrinsics.yaml @@ -0,0 +1,15 @@ +Parameters: + AliasName: + Type: String + Default: live + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: + Ref: AliasName + diff --git a/tests/functional/commands/validate/lib/models/function_with_condition.yaml b/tests/functional/commands/validate/lib/models/function_with_condition.yaml new file mode 100644 index 0000000000..059ea737b4 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_condition.yaml @@ -0,0 +1,13 @@ +Conditions: + TestCondition: + Fn::Equals: + - test + - test +Resources: + ConditionFunction: + Type: 'AWS::Serverless::Function' + Condition: "TestCondition" + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/function_with_custom_codedeploy_deployment_preference.yaml b/tests/functional/commands/validate/lib/models/function_with_custom_codedeploy_deployment_preference.yaml new file mode 100644 index 0000000000..1a6a8606a7 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_custom_codedeploy_deployment_preference.yaml @@ -0,0 +1,96 @@ +Mappings: + DeploymentPreferenceMap: + prod: + DeploymentPreference: + AllAtOnce + beta: + DeploymentPreference: + CustomDeployment + +Parameters: + Stage: + Type: String + Default: 'beta' + Deployment: + Type: String + Default: 'AllAtOnce' + Custom: + Type: String + Default: 'CustomDeployment' + +Conditions: + MyCondition: + Fn::Equals: + - true + - false + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: TestDeploymentConfiguration + + CustomWithFindInMap: # Doesn't work + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !FindInMap [DeploymentPreferenceMap, !Ref Stage, DeploymentPreference] + + CustomWithCondition: # Works + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !If [MyCondition, TestDeploymentConfiguration, AllAtOnce] + + CustomWithCondition2: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !If [MyCondition, !Sub "${Deployment}", !Ref Custom] + + NormalWithSub: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Sub ${Deployment} + + CustomWithSub: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Sub ${Custom} + + NormalWithRef: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Ref Deployment \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/function_with_custom_conditional_codedeploy_deployment_preference.yaml b/tests/functional/commands/validate/lib/models/function_with_custom_conditional_codedeploy_deployment_preference.yaml new file mode 100644 index 0000000000..e1a53328eb --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_custom_conditional_codedeploy_deployment_preference.yaml @@ -0,0 +1,19 @@ +AWSTemplateFormatVersion : '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Parameters: + EnvType: + Default: dev + Type: String +Conditions: + IsDevEnv: !Equals [!Ref EnvType, dev] + IsDevEnv2: !Equals [!Ref EnvType, prod] +Resources: + HelloWorldFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: nodejs8.10 + CodeUri: s3://bucket/key + AutoPublishAlias: live + DeploymentPreference: + Type: !If [IsDevEnv, !If [IsDevEnv2, AllAtOnce, TestCustomDeploymentConfig], Canary10Percent15Minutes] diff --git a/tests/functional/commands/validate/lib/models/function_with_deployment_and_custom_role.yaml b/tests/functional/commands/validate/lib/models/function_with_deployment_and_custom_role.yaml new file mode 100644 index 0000000000..448b0fdc05 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_deployment_and_custom_role.yaml @@ -0,0 +1,40 @@ +Globals: + Function: + AutoPublishAlias: live + DeploymentPreference: + Type: AllAtOnce + +Resources: + + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + FunctionWithRole: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Role: !GetAtt DeploymentRole.Arn + + DeploymentRole: + Type: AWS::IAM::Role + Properties: + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Action: + - sts:AssumeRole + Effect: Allow + Principal: + Service: + - codedeploy.amazonaws.com + + + diff --git a/tests/functional/commands/validate/lib/models/function_with_deployment_no_service_role.yaml b/tests/functional/commands/validate/lib/models/function_with_deployment_no_service_role.yaml new file mode 100644 index 0000000000..ae40a6a00b --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_deployment_no_service_role.yaml @@ -0,0 +1,40 @@ +Globals: + Function: + AutoPublishAlias: live + DeploymentPreference: + Type: AllAtOnce + Role: !Ref DeploymentRole + +Resources: + + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + OtherFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + DeploymentRole: + Type: AWS::IAM::Role + Properties: + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Action: + - sts:AssumeRole + Effect: Allow + Principal: + Service: + - codedeploy.amazonaws.com + + + diff --git a/tests/functional/commands/validate/lib/models/function_with_deployment_preference.yaml b/tests/functional/commands/validate/lib/models/function_with_deployment_preference.yaml new file mode 100644 index 0000000000..19eaa94311 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_deployment_preference.yaml @@ -0,0 +1,10 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/function_with_deployment_preference_all_parameters.yaml b/tests/functional/commands/validate/lib/models/function_with_deployment_preference_all_parameters.yaml new file mode 100644 index 0000000000..00fdce01a9 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_deployment_preference_all_parameters.yaml @@ -0,0 +1,44 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Enabled: true + Type: Linear10PercentEvery1Minute + Hooks: + PreTraffic: !Ref MySanityTestFunction + PostTraffic: !Ref MyValidationTestFunction + Alarms: + - !Ref MyCloudWatchAlarm + + MySanityTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/mySanityTestFunction.zip + DeploymentPreference: + Enabled: false + + MyValidationTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/myValidationTestFunction.zip + DeploymentPreference: + Enabled: false + + MyCloudWatchAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + ComparisonOperator: GreaterThanThreshold + EvaluationPeriods: 1 + MetricName: MyMetric + Namespace: AWS/EC2 + Period: 300 + Threshold: 10 diff --git a/tests/functional/commands/validate/lib/models/function_with_deployment_preference_multiple_combinations.yaml b/tests/functional/commands/validate/lib/models/function_with_deployment_preference_multiple_combinations.yaml new file mode 100644 index 0000000000..588983aa04 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_deployment_preference_multiple_combinations.yaml @@ -0,0 +1,61 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + + MinimalFunctionWithMinimalDeploymentPreference: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeployment + DeploymentPreference: + Type: Canary10Percent5Minutes + + MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeploymentwithhooksandalarms + DeploymentPreference: + Type: Linear10PercentEvery2Minutes + Hooks: + PreTraffic: !Ref MySanityTestFunction + PostTraffic: !Ref MyValidationTestFunction + Alarms: + - !Ref MyCloudWatchAlarm + + MySanityTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/mySanityTestFunction.zip + DeploymentPreference: + Enabled: false + + MyValidationTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/myValidationTestFunction.zip + DeploymentPreference: + Enabled: false + + MyCloudWatchAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + ComparisonOperator: GreaterThanThreshold + EvaluationPeriods: 1 + MetricName: MyMetric + Namespace: AWS/EC2 + Period: 300 + Threshold: 10 diff --git a/tests/functional/commands/validate/lib/models/function_with_disabled_deployment_preference.yaml b/tests/functional/commands/validate/lib/models/function_with_disabled_deployment_preference.yaml new file mode 100644 index 0000000000..092fd455ed --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_disabled_deployment_preference.yaml @@ -0,0 +1,11 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Enabled: false + Type: AllAtOnce \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/function_with_dlq.yaml b/tests/functional/commands/validate/lib/models/function_with_dlq.yaml new file mode 100644 index 0000000000..217777345b --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_dlq.yaml @@ -0,0 +1,21 @@ +Transform: "AWS::Serverless-2016-10-31" +Resources: + MySnsDlqLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python2.7 + CodeUri: s3://sam-demo-bucket/hello.zip + DeadLetterQueue: + Type: SNS + TargetArn: arn + + MySqsDlqLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python2.7 + CodeUri: s3://sam-demo-bucket/hello.zip + DeadLetterQueue: + Type: SQS + TargetArn: arn diff --git a/tests/functional/commands/validate/lib/models/function_with_global_layers.yaml b/tests/functional/commands/validate/lib/models/function_with_global_layers.yaml new file mode 100644 index 0000000000..2b4d6eb32f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_global_layers.yaml @@ -0,0 +1,19 @@ +Globals: + Function: + Layers: + - arn:aws:lambda:us-east-1:123456789101:layer:layer1:1 + - arn:aws:lambda:us-east-1:123456789101:layer:layer2:1 + +# Note: there is a limit to the number of layers that a function can reference. +Resources: + ManyLayersFunc: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.6 + Layers: + - arn:aws:lambda:us-east-1:123456789101:layer:layer3:1 + - arn:aws:lambda:us-east-1:123456789101:layer:layer4:1 + - arn:aws:lambda:us-east-1:123456789101:layer:layer5:1 + diff --git a/tests/functional/commands/validate/lib/models/function_with_kmskeyarn.yaml b/tests/functional/commands/validate/lib/models/function_with_kmskeyarn.yaml new file mode 100644 index 0000000000..4679b19a06 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_kmskeyarn.yaml @@ -0,0 +1,34 @@ +Resources: + FunctionWithKeyArn: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + KmsKeyArn: thisIsaKey + + FunctionWithReferenceToKeyArn: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + KmsKeyArn: + Ref: myKey + + myKey: + Type: "AWS::KMS::Key" + Properties: + Description: "A sample key" + KeyPolicy: + Version: "2012-10-17" + Id: "key-default-1" + Statement: + - + Sid: "Allow administration of the key" + Effect: "Allow" + Principal: + AWS: "arn:aws:iam::123456789012:user/Alice" + Action: + - "kms:Create*" + Resource: "*" diff --git a/tests/functional/commands/validate/lib/models/function_with_layers.yaml b/tests/functional/commands/validate/lib/models/function_with_layers.yaml new file mode 100644 index 0000000000..1e34324d02 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_layers.yaml @@ -0,0 +1,42 @@ +Resources: + MinimalLayerFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Layers: + - arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1 + + FunctionNoLayerVersion: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Layers: + - arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1 + + FunctionLayerWithSubIntrinsic: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Layers: + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1 + - Fn::Sub: arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1 + + FunctionReferencesLayer: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Layers: + - !Ref MyLayer + + MyLayer: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip diff --git a/tests/functional/commands/validate/lib/models/function_with_many_layers.yaml b/tests/functional/commands/validate/lib/models/function_with_many_layers.yaml new file mode 100644 index 0000000000..78ba2bc4ab --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_many_layers.yaml @@ -0,0 +1,18 @@ +Resources: + ManyLayersFunc: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Layers: + - arn:aws:lambda:us-east-1:123456789101:layer:z:1 + - !Sub arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1 + - arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1 + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1 + - !Ref MyLayer + + MyLayer: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip diff --git a/tests/functional/commands/validate/lib/models/function_with_permissions_boundary.yaml b/tests/functional/commands/validate/lib/models/function_with_permissions_boundary.yaml new file mode 100644 index 0000000000..5cad58b7f9 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_permissions_boundary.yaml @@ -0,0 +1,9 @@ +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary + diff --git a/tests/functional/commands/validate/lib/models/function_with_policy_templates.yaml b/tests/functional/commands/validate/lib/models/function_with_policy_templates.yaml new file mode 100644 index 0000000000..34fd86683f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_policy_templates.yaml @@ -0,0 +1,55 @@ +Parameters: + FunctionNameParam: + Type: String + +Resources: + + OnePolicyTemplate: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: + SQSPollerPolicy: + QueueName: + Fn::Sub: ["Some${value}", {"value": "KeyId"}] + + # Extra parameters will be skipped, and not appear in output + ExtraParam1: Value1 + ExtraParam2: Value2 + + MultiplePolicyTemplates: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: + - SQSPollerPolicy: + QueueName: "Somekey" + - LambdaInvokePolicy: + FunctionName: "Some function" + + AllCombinations: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + Policies: + # Inline statement + - Statement: + - Action: [ 'dynamodb:*' ] + Effect: Allow + Resource: '*' + # Regular managed policy + - AmazonDynamoDBFullAccess + + - LambdaInvokePolicy: + FunctionName: + # Refer to something + Ref: FunctionNameParam + + # Regular managed policy + - AWSLambdaRole diff --git a/tests/functional/commands/validate/lib/models/function_with_resource_refs.yaml b/tests/functional/commands/validate/lib/models/function_with_resource_refs.yaml new file mode 100644 index 0000000000..02732661c6 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_resource_refs.yaml @@ -0,0 +1,52 @@ +# Test to verify that resource references available on the Function are properly resolved +# Currently supported references are: +# - Alias +# +# Use them by appending the property to LogicalId of the function + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + + FunctionWithoutAlias: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + MyBucket: + Type: AWS::S3::Bucket + Properties: + Name: + Fn::GetAtt: ["MinimalFunction.Alias", "Name"] + +Outputs: + AliasArn: + Value: !Ref MinimalFunction.Alias + + AliasName: + Value: !GetAtt MinimalFunction.Alias.Name + + # Alias doesn't exist for this function. This reference must not resolve + MustNotResolve: + Value: !GetAtt FunctionWithoutAlias.Alias.Name + + AliasInSub: + Value: + Fn::Sub: ["Hello ${MinimalFunction.Alias} ${MinimalFunction.Alias.Name} ${SomeValue}", {"SomeValue": "World"}] + + VersionArn: + Value: !Ref MinimalFunction.Version + VersionNumber: + Value: + Fn::GetAtt: ["MinimalFunction.Version", "Version"] + + UnResolvedVersion: + Value: + Ref: FunctionWithoutAlias.Version diff --git a/tests/functional/commands/validate/lib/models/function_with_sns_event_source_all_parameters.yaml b/tests/functional/commands/validate/lib/models/function_with_sns_event_source_all_parameters.yaml new file mode 100644 index 0000000000..a745b2f9c8 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/function_with_sns_event_source_all_parameters.yaml @@ -0,0 +1,28 @@ +Resources: + MyAwesomeFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + Events: + NotificationTopic: + Type: SNS + Properties: + Topic: topicArn + FilterPolicy: + store: + - example_corp + event: + - anything-but: order_cancelled + customer_interests: + - rugby + - football + - baseball + price_usd: + - numeric: + - ">=" + - 100 + + diff --git a/tests/functional/commands/validate/lib/models/global_handle_path_level_parameter.yaml b/tests/functional/commands/validate/lib/models/global_handle_path_level_parameter.yaml new file mode 100644 index 0000000000..2bd9995fbf --- /dev/null +++ b/tests/functional/commands/validate/lib/models/global_handle_path_level_parameter.yaml @@ -0,0 +1,64 @@ +Globals: + Api: + Name: "some api" + CacheClusterEnabled: True + CacheClusterSize: "1.6" + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + Variables: + SomeVar: Value + +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: SomeStage + DefinitionBody: + swagger: 2.0 + info: + version: '1.0' + title: !Ref AWS::StackName + paths: + "/": + parameters: + - name: domain + in: path + description: Application domain + type: string + required: true + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations + responses: {} + + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/globals_for_api.yaml b/tests/functional/commands/validate/lib/models/globals_for_api.yaml new file mode 100644 index 0000000000..5d3a956322 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/globals_for_api.yaml @@ -0,0 +1,58 @@ +Globals: + Api: + Name: "some api" + CacheClusterEnabled: True + CacheClusterSize: "1.6" + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: !GetAtt MyUserPool.Arn + Variables: + SomeVar: Value + +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: SomeStage + DefinitionBody: + swagger: 2.0 + info: + version: '1.0' + title: !Ref AWS::StackName + paths: + "/": + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations + responses: {} + + MyUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: UserPoolName + Policies: + PasswordPolicy: + MinimumLength: 8 + UsernameAttributes: + - email + Schema: + - AttributeDataType: String + Name: email + Required: false \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/globals_for_function.yaml b/tests/functional/commands/validate/lib/models/globals_for_function.yaml new file mode 100644 index 0000000000..f3acd0e898 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/globals_for_function.yaml @@ -0,0 +1,52 @@ +Globals: + Function: + CodeUri: s3://global-bucket/global.zip + Handler: hello.handler + Runtime: python2.7 + MemorySize: 1024 + Timeout: 30 + VpcConfig: + SecurityGroupIds: + - sg-edcd9784 + SubnetIds: + - sub-id-2 + Environment: + Variables: + Var1: value1 + Var2: value2 + Tags: + tag1: value1 + Tracing: Active + AutoPublishAlias: live + PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary + Layers: + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1 + ReservedConcurrentExecutions: 50 + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + + FunctionWithOverrides: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: index.handler + Runtime: nodejs4.3 + MemorySize: 512 + Timeout: 100 + VpcConfig: + SecurityGroupIds: + - sg-123 + Environment: + Variables: + Var3: value3 + Tags: + newtag1: newvalue1 + Tracing: PassThrough + AutoPublishAlias: prod + PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary + Layers: + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2 + ReservedConcurrentExecutions: 100 + diff --git a/tests/functional/commands/validate/lib/models/globals_for_function_path.yaml b/tests/functional/commands/validate/lib/models/globals_for_function_path.yaml new file mode 100644 index 0000000000..9eaa179fae --- /dev/null +++ b/tests/functional/commands/validate/lib/models/globals_for_function_path.yaml @@ -0,0 +1,51 @@ +Globals: + Function: + CodeUri: ./ + Handler: hello.handler + Runtime: python2.7 + MemorySize: 1024 + Timeout: 30 + VpcConfig: + SecurityGroupIds: + - sg-edcd9784 + SubnetIds: + - sub-id-2 + Environment: + Variables: + Var1: value1 + Var2: value2 + Tags: + tag1: value1 + Tracing: Active + AutoPublishAlias: live + PermissionsBoundary: arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary + Layers: + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1 + ReservedConcurrentExecutions: 50 + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + + FunctionWithOverrides: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: index.handler + Runtime: nodejs4.3 + MemorySize: 512 + Timeout: 100 + VpcConfig: + SecurityGroupIds: + - sg-123 + Environment: + Variables: + Var3: value3 + Tags: + newtag1: newvalue1 + Tracing: PassThrough + AutoPublishAlias: prod + PermissionsBoundary: arn:aws:1234:iam:boundary/OverridePermissionsBoundary + Layers: + - !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2 + ReservedConcurrentExecutions: 100 diff --git a/tests/functional/commands/validate/lib/models/globals_for_simpletable.yaml b/tests/functional/commands/validate/lib/models/globals_for_simpletable.yaml new file mode 100644 index 0000000000..6a03a75ed7 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/globals_for_simpletable.yaml @@ -0,0 +1,8 @@ +Globals: + SimpleTable: + SSESpecification: + SSEEnabled: true + +Resources: + MinimalTable: + Type: AWS::Serverless::SimpleTable \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/implicit_and_explicit_api_with_conditions.yaml b/tests/functional/commands/validate/lib/models/implicit_and_explicit_api_with_conditions.yaml new file mode 100644 index 0000000000..5303f53be5 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/implicit_and_explicit_api_with_conditions.yaml @@ -0,0 +1,93 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Description: A template to test for API condition handling with a mix of explicit and implicit api events. +Conditions: + implicithello1condition: + Fn::Equals: + - true + - false + implicithello2condition: + Fn::Equals: + - true + - false + explicithello1condition: + Fn::Equals: + - true + - false + explicithello2condition: + Fn::Equals: + - true + - false + +Resources: + implicithello1: + Type: 'AWS::Serverless::Function' + Condition: implicithello1condition + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /implicit/hello1 + Method: get + implicithello2: + Type: 'AWS::Serverless::Function' + Condition: implicithello2condition + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /implicit/hello2 + Method: get + + explicitapi: + Type: 'AWS::Serverless::Api' + Properties: + StageName: Prod + explicithello1: + Type: 'AWS::Serverless::Function' + Condition: explicithello1condition + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + RestApiId: !Ref explicitapi + Path: /explicit/hello1 + Method: get + explicithello2: + Type: 'AWS::Serverless::Function' + Condition: explicithello2condition + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + RestApiId: !Ref explicitapi + Path: /explicit/hello2 + Method: get diff --git a/tests/functional/commands/validate/lib/models/implicit_api.yaml b/tests/functional/commands/validate/lib/models/implicit_api.yaml new file mode 100644 index 0000000000..c5b6422249 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/implicit_api.yaml @@ -0,0 +1,38 @@ +Resources: + RestApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/todo_list.zip + Handler: index.restapi + Runtime: nodejs4.3 + Policies: AmazonDynamoDBFullAccess + Events: + AddItem: + Type: Api + Properties: + Path: /add + Method: post + CompleteItem: + Type: Api + Properties: + Path: /complete + Method: POST + GetList: + Type: Api + Properties: + Path: /getlist + Method: get + + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/todo_list.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Policies: AmazonDynamoDBReadOnlyAccess + Events: + GetHtml: + Type: Api + Properties: + Path: /{proxy+} + Method: any diff --git a/tests/functional/commands/validate/lib/models/implicit_api_with_auth_and_conditions_max.yaml b/tests/functional/commands/validate/lib/models/implicit_api_with_auth_and_conditions_max.yaml new file mode 100644 index 0000000000..61d2751a21 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/implicit_api_with_auth_and_conditions_max.yaml @@ -0,0 +1,164 @@ +Globals: + Api: + Auth: + DefaultAuthorizer: MyCognitoAuth + Authorizers: + MyCognitoAuth: + UserPoolArn: arn:aws:1 + Identity: + Header: MyAuthorizationHeader + ValidationExpression: myauthvalidationexpression + + MyCognitoAuthMultipleUserPools: + UserPoolArn: + - arn:aws:2 + - arn:aws:3 + Identity: + Header: MyAuthorizationHeader2 + ValidationExpression: myauthvalidationexpression2 + + MyLambdaTokenAuth: + FunctionPayloadType: TOKEN + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Header: MyCustomAuthHeader + ValidationExpression: mycustomauthexpression + ReauthorizeEvery: 20 + + MyLambdaTokenAuthNoneFunctionInvokeRole: + FunctionArn: arn:aws + FunctionInvokeRole: NONE + Identity: + ReauthorizeEvery: 0 + + MyLambdaRequestAuth: + FunctionPayloadType: REQUEST + FunctionArn: arn:aws + FunctionInvokeRole: arn:aws:iam::123456789012:role/S3Access + Identity: + Headers: + - Authorization1 + QueryStrings: + - Authorization2 + StageVariables: + - Authorization3 + Context: + - Authorization4 + ReauthorizeEvery: 0 + +Conditions: + FunctionCondition: + Fn::Equals: + - true + - false + FunctionCondition2: + Fn::Equals: + - true + - false + FunctionCondition3: + Fn::Equals: + - true + - false + FunctionCondition4: + Fn::Equals: + - true + - false + FunctionCondition5: + Fn::Equals: + - true + - false + FunctionCondition6: + Fn::Equals: + - true + - false + +Resources: + MyFunction: + Type: AWS::Serverless::Function + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithNoAuthorizer: + Type: Api + Properties: + Path: / + Method: get + Auth: + Authorizer: NONE + MyFunction2: + Type: AWS::Serverless::Function + Condition: FunctionCondition2 + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithCognitoMultipleUserPoolsAuthorizer: + Type: Api + Properties: + Path: /users + Method: post + Auth: + Authorizer: MyCognitoAuthMultipleUserPools + MyFunction3: + Type: AWS::Serverless::Function + Condition: FunctionCondition3 + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithLambdaTokenAuthorizer: + Type: Api + Properties: + Path: /users + Method: get + Auth: + Authorizer: MyLambdaTokenAuth + MyFunction4: + Type: AWS::Serverless::Function + Condition: FunctionCondition4 + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithLambdaTokenAuthorizer: + Type: Api + Properties: + Path: /users + Method: patch + Auth: + Authorizer: MyLambdaTokenAuthNoneFunctionInvokeRole + MyFunction5: + Type: AWS::Serverless::Function + Condition: FunctionCondition5 + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithLambdaRequestAuthorizer: + Type: Api + Properties: + Path: /users + Method: delete + Auth: + Authorizer: MyLambdaRequestAuth + MyFunction6: + Type: AWS::Serverless::Function + Condition: FunctionCondition6 + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.handler + Runtime: nodejs8.10 + Events: + WithDefaultAuthorizer: + Type: Api + Properties: + Path: /users + Method: put \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/implicit_api_with_many_conditions.yaml b/tests/functional/commands/validate/lib/models/implicit_api_with_many_conditions.yaml new file mode 100644 index 0000000000..9ee7cc3deb --- /dev/null +++ b/tests/functional/commands/validate/lib/models/implicit_api_with_many_conditions.yaml @@ -0,0 +1,226 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: 'AWS::Serverless-2016-10-31' +Description: A template to test for implicit API condition handling. +Conditions: + MyCondition: + Fn::Equals: + - true + - false + Cond: + Fn::Equals: + - true + - false + Cond1: + Fn::Equals: + - true + - false + Cond2: + Fn::Equals: + - true + - false + Cond3: + Fn::Equals: + - true + - false + Cond4: + Fn::Equals: + - true + - false + Cond5: + Fn::Equals: + - true + - false + Cond6: + Fn::Equals: + - true + - false + Cond7: + Fn::Equals: + - true + - false + Cond8: + Fn::Equals: + - true + - false + Cond9: + Fn::Equals: + - true + - false + +Resources: + hello: + Type: 'AWS::Serverless::Function' + Condition: MyCondition + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub + Method: get + helloworld: + Type: 'AWS::Serverless::Function' + Condition: Cond + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub + Method: post + helloworld1: + Type: 'AWS::Serverless::Function' + Condition: Cond1 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub1 + Method: post + helloworld2: + Type: 'AWS::Serverless::Function' + Condition: Cond2 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub2 + Method: post + helloworld3: + Type: 'AWS::Serverless::Function' + Condition: Cond3 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub3 + Method: post + helloworld4: + Type: 'AWS::Serverless::Function' + Condition: Cond4 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub4 + Method: post + helloworld5: + Type: 'AWS::Serverless::Function' + Condition: Cond5 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub5 + Method: post + helloworld6: + Type: 'AWS::Serverless::Function' + Condition: Cond6 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub6 + Method: post + helloworld7: + Type: 'AWS::Serverless::Function' + Condition: Cond7 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub7 + Method: post + helloworld8: + Type: 'AWS::Serverless::Function' + Condition: Cond8 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub8 + Method: post + helloworld9: + Type: 'AWS::Serverless::Function' + Condition: Cond9 + Properties: + Handler: index.handler + Runtime: nodejs8.10 + MemorySize: 128 + Timeout: 3 + InlineCode: | + exports.handler = async () => ‘Hello World!' + Events: + ApiEvent: + Type: Api + Properties: + Path: /sub9 + Method: post diff --git a/tests/functional/commands/validate/lib/models/implicit_api_with_serverless_rest_api_resource.yaml b/tests/functional/commands/validate/lib/models/implicit_api_with_serverless_rest_api_resource.yaml new file mode 100644 index 0000000000..be49ab4645 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/implicit_api_with_serverless_rest_api_resource.yaml @@ -0,0 +1,45 @@ +Resources: + RestApiFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/todo_list.zip + Handler: index.restapi + Runtime: nodejs4.3 + Policies: AmazonDynamoDBFullAccess + Events: + AddItem: + Type: Api + Properties: + Path: /add + Method: post + CompleteItem: + Type: Api + Properties: + Path: /complete + Method: POST + GetList: + Type: Api + Properties: + Path: /getlist + Method: get + + GetHtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/todo_list.zip + Handler: index.gethtml + Runtime: nodejs4.3 + Policies: AmazonDynamoDBReadOnlyAccess + Events: + GetHtml: + Type: Api + Properties: + Path: /{proxy+} + Method: any + + ServerlessRestApi: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 diff --git a/tests/functional/commands/validate/lib/models/intrinsic_functions.yaml b/tests/functional/commands/validate/lib/models/intrinsic_functions.yaml new file mode 100644 index 0000000000..a17a2378c1 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/intrinsic_functions.yaml @@ -0,0 +1,173 @@ +# SAM template using intrinsic function on every property that supports it. +# Translator should handle it properly +Parameters: + CodeBucket: + Type: String + Default: sam-demo-bucket + FunctionName: + Type: String + Default: MySuperFunctionName + TracingConfigParam: + Type: String + Default: PassThrough + MyExplicitApiName: + Type: String + Default: SomeName + CodeKey: + Type: String + Default: "key" + +Conditions: + TrueCondition: + Fn::Equals: + - true + - true + +Resources: + MyFunction: + Type: 'AWS::Serverless::Function' + Properties: + FunctionName: + Ref: FunctionName + CodeUri: + Bucket: + Ref: CodeBucket + Key: + "Fn::Sub": "code.zip.${CodeKey}" + Version: + "Fn::Join": ["", ["some", "version"]] + + Handler: + "Fn::Sub": ["${filename}.handler", {filename: "index"}] + + Runtime: + "Fn::Join": ["", ["nodejs", "4.3"]] + + Role: + "Fn::GetAtt": ["MyNewRole", "Arn"] + + Tracing: + Ref: TracingConfigParam + + Events: + MyApi: + Type: Api + Properties: + Path: / + Method: GET + RestApiId: + "Ref": "MyExplicitApi" + + MyExplicitApi: + Type: AWS::Serverless::Api + Properties: + Name: + Ref: MyExplicitApiName + DefinitionUri: s3://sam-demo-bucket/swagger.yaml + StageName: dev + Variables: + FunctionName: + Fn::Sub: "${MyFunction}" + Var2: + Fn::Join: ["join ", ["some value ", "with some other value"]] + + FunctionWithExplicitS3Uri: + Type: AWS::Serverless::Function + Properties: + Handler: stream.ddb_handler + Runtime: python2.7 + CodeUri: + Bucket: mybucket + Key: mykey + Version: MyVersion + + ApiWithExplicitS3Uri: + Type: AWS::Serverless::Api + Condition: TrueCondition + Properties: + StageName: dev + DefinitionUri: + Bucket: mybucket + Key: mykey + Version: myversion + + DynamoDBFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/streams.zip + Handler: stream.ddb_handler + Runtime: python2.7 + Events: + MyDDBStream: + Type: DynamoDB + Properties: + Stream: + Fn::GetAtt: [MyTable, "StreamArn"] + BatchSize: 200 + StartingPosition: LATEST + + MyTable: + Type: AWS::DynamoDB::Table + Properties: + + AttributeDefinitions: + - { AttributeName : id, AttributeType : S } + + KeySchema: + - { "AttributeName" : "id", "KeyType" : "HASH"} + + ProvisionedThroughput: + ReadCapacityUnits: 5 + WriteCapacityUnits: 5 + + StreamSpecification: + StreamViewType: "NEW_IMAGE" + + MySqsDlqLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python2.7 + CodeUri: s3://sam-demo-bucket/hello.zip + DeadLetterQueue: + Type: SQS + TargetArn: + Fn::GetAtt: + - SqsDlqQueue + - Arn + + SqsDlqQueue: + Type: AWS::SQS::Queue + + MySnsDlqLambdaFunction: + Type: AWS::Serverless::Function + Properties: + Handler: index.handler + Runtime: python2.7 + CodeUri: s3://sam-demo-bucket/hello.zip + DeadLetterQueue: + Type: SNS + TargetArn: + Ref: SnsDlqQueue + + SnsDlqQueue: + Type: AWS::SNS::Topic + + MyNewRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: ['sts:AssumeRole'] + Effect: Allow + Principal: + Service: [lambda.amazonaws.com] + Version: '2012-10-17' + Policies: + - PolicyDocument: + Statement: + - Action: ['cloudwatch:*', 'logs:*'] + Effect: Allow + Resource: '*' + Version: '2012-10-17' + PolicyName: lambdaRole diff --git a/tests/functional/commands/validate/lib/models/iot_rule.yaml b/tests/functional/commands/validate/lib/models/iot_rule.yaml new file mode 100644 index 0000000000..3d3b50cbcd --- /dev/null +++ b/tests/functional/commands/validate/lib/models/iot_rule.yaml @@ -0,0 +1,26 @@ +# File: sam.yml +# Version: 0.9 + +AWSTemplateFormatVersion: '2010-09-09' +Parameters: {} +Resources: + IoTRuleFunc: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Description: Created by SAM + Events: + MyIoTRule: + Type: IoTRule + Properties: + Sql: SELECT * FROM 'topic/test' + AwsIotSqlVersion: beta + MyOtherIoTRule: + Type: IoTRule + Properties: + Sql: SELECT * FROM 'topic/test' + Handler: index.handler + MemorySize: 1024 + Runtime: nodejs4.3 + Timeout: 3 + diff --git a/tests/functional/commands/validate/lib/models/layers_all_properties.yaml b/tests/functional/commands/validate/lib/models/layers_all_properties.yaml new file mode 100644 index 0000000000..03fef5dbc2 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/layers_all_properties.yaml @@ -0,0 +1,38 @@ +Parameters: + LayerDeleteParam: + Type: String + Default: Delete + +Resources: + MyLayer: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://bucket/key + RetentionPolicy: !Ref LayerDeleteParam + + MyLayerWithAName: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://bucket/key + LayerName: DifferentLayerName + + MyFunction: + Type: "AWS::Serverless::Function" + Properties: + CodeUri: s3://bucket/key + Handler: app.handler + Runtime: python3.6 + Layers: + - !Ref MyLayer + +Outputs: + LayerName: + Value: !Ref MyLayer + FunctionName: + Value: !Ref MyFunction + FunctionAtt: + Value: !GetAtt MyFunction.Arn + LayerSub: + Value: !Sub ${MyLayer} + FunctionSub: + Value: !Sub ${MyFunction} diff --git a/tests/functional/commands/validate/lib/models/layers_with_intrinsics.yaml b/tests/functional/commands/validate/lib/models/layers_with_intrinsics.yaml new file mode 100644 index 0000000000..70a9c8764f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/layers_with_intrinsics.yaml @@ -0,0 +1,48 @@ +Parameters: + LayerNameParam: + Type: String + Default: SomeLayerName + LayerLicenseInfo: + Type: String + Default: MIT-0 License + LayerRuntimeList: + Type: CommaDelimitedList + +Resources: + LayerWithLicenseIntrinsic: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + LicenseInfo: !Ref LayerLicenseInfo + + LayerWithRuntimesIntrinsic: + Type: 'AWS::Serverless::LayerVersion' + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + CompatibleRuntimes: + Ref: LayerRuntimeList + + LayerWithNameIntrinsic: + Type: AWS::Serverless::LayerVersion + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + LayerName: !Ref LayerNameParam + + LayerWithSubNameIntrinsic: + Type: AWS::Serverless::LayerVersion + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + LayerName: !Sub layer-${LayerNameParam} + + LayerWithRefNameIntrinsicRegion: + Type: AWS::Serverless::LayerVersion + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + LayerName: !Ref 'AWS::Region' + + LayerWithSubNameIntrinsicRegion: + Type: AWS::Serverless::LayerVersion + Properties: + ContentUri: s3://sam-demo-bucket/layer.zip + LayerName: !Sub 'layer-${AWS::Region}' + diff --git a/tests/functional/commands/validate/lib/models/no_implicit_api_with_serverless_rest_api_resource.yaml b/tests/functional/commands/validate/lib/models/no_implicit_api_with_serverless_rest_api_resource.yaml new file mode 100644 index 0000000000..0998b13b38 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/no_implicit_api_with_serverless_rest_api_resource.yaml @@ -0,0 +1,74 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + ServerlessRestApi: + Type: AWS::ApiGateway::RestApi + Properties: + Body: + info: + version: '1.0' + title: + Ref: AWS::StackName + paths: + "/add": + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: + Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations + responses: {} + "/{proxy+}": + x-amazon-apigateway-any-method: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: + Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations + responses: {} + "/getlist": + get: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: + Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations + responses: {} + "/complete": + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: + Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations + responses: {} + swagger: '2.0' + + Images: + Type: AWS::S3::Bucket + + RestApiFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.6 + + GetHtmlFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python3.6 \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/s3.yaml b/tests/functional/commands/validate/lib/models/s3.yaml new file mode 100644 index 0000000000..cfead59f4c --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3.yaml @@ -0,0 +1,17 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket diff --git a/tests/functional/commands/validate/lib/models/s3_create_remove.yaml b/tests/functional/commands/validate/lib/models/s3_create_remove.yaml new file mode 100644 index 0000000000..af1abaad68 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_create_remove.yaml @@ -0,0 +1,25 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: + - s3:ObjectCreated:* + - s3:ObjectRemoved:* + + Images: + Type: AWS::S3::Bucket + Properties: + BucketName: "BucketNameParameter" + BucketEncryption: + ServerSideEncryptionConfiguration: + - ServerSideEncryptionByDefault: + SSEAlgorithm: AES256 diff --git a/tests/functional/commands/validate/lib/models/s3_existing_lambda_notification_configuration.yaml b/tests/functional/commands/validate/lib/models/s3_existing_lambda_notification_configuration.yaml new file mode 100644 index 0000000000..fd9ef06f75 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_existing_lambda_notification_configuration.yaml @@ -0,0 +1,23 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket + Properties: + NotificationConfiguration: + LambdaConfigurations: + - Function: + Fn::GetAtt: [ThumbnailFunction, Arn] + Event: s3:ObjectCreated:* diff --git a/tests/functional/commands/validate/lib/models/s3_existing_other_notification_configuration.yaml b/tests/functional/commands/validate/lib/models/s3_existing_other_notification_configuration.yaml new file mode 100644 index 0000000000..b181bb7a6d --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_existing_other_notification_configuration.yaml @@ -0,0 +1,22 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket + Properties: + NotificationConfiguration: + TopicConfigurations: + - Topic: my-super-awesome-topic + Event: s3:ObjectRemoved:* diff --git a/tests/functional/commands/validate/lib/models/s3_filter.yaml b/tests/functional/commands/validate/lib/models/s3_filter.yaml new file mode 100644 index 0000000000..a9aa41b4a0 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_filter.yaml @@ -0,0 +1,22 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + Filter: + S3Key: + Rules: + - Name: name + Value: value + + Images: + Type: AWS::S3::Bucket diff --git a/tests/functional/commands/validate/lib/models/s3_multiple_events_same_bucket.yaml b/tests/functional/commands/validate/lib/models/s3_multiple_events_same_bucket.yaml new file mode 100644 index 0000000000..330db80538 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_multiple_events_same_bucket.yaml @@ -0,0 +1,28 @@ +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucketCreates: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + ImageBucketDeletes: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectRemoved:* + Filter: + S3Key: + Rules: + - Name: suffix + Value: .jpg + + Images: + Type: AWS::S3::Bucket diff --git a/tests/functional/commands/validate/lib/models/s3_multiple_functions.yaml b/tests/functional/commands/validate/lib/models/s3_multiple_functions.yaml new file mode 100644 index 0000000000..f452f8fb9f --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_multiple_functions.yaml @@ -0,0 +1,37 @@ +Resources: + FunctionOne: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + FunctionTwo: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket + Properties: + PublicAccessBlockConfiguration: + BlockPublicAcls: true + BlockPublicPolicy: true + IgnorePublicAcls: true + RestrictPublicBuckets: true diff --git a/tests/functional/commands/validate/lib/models/s3_with_condition.yaml b/tests/functional/commands/validate/lib/models/s3_with_condition.yaml new file mode 100644 index 0000000000..e83ec38f9d --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_with_condition.yaml @@ -0,0 +1,23 @@ +Conditions: + MyCondition: + Fn::Equals: + - yes + - no +Resources: + ThumbnailFunction: + Type: AWS::Serverless::Function + Condition: MyCondition + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket diff --git a/tests/functional/commands/validate/lib/models/s3_with_dependsOn.yaml b/tests/functional/commands/validate/lib/models/s3_with_dependsOn.yaml new file mode 100644 index 0000000000..af5b92e513 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/s3_with_dependsOn.yaml @@ -0,0 +1,21 @@ +Resources: + Topic: + Type: AWS::SNS::Topic + + ThumbnailFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/thumbnails.zip + Handler: index.generate_thumbails + Runtime: nodejs4.3 + Events: + ImageBucket: + Type: S3 + Properties: + Bucket: + Ref: Images + Events: s3:ObjectCreated:* + + Images: + Type: AWS::S3::Bucket + DependsOn: Topic diff --git a/tests/functional/commands/validate/lib/models/simple_table_ref_parameter_intrinsic.yaml b/tests/functional/commands/validate/lib/models/simple_table_ref_parameter_intrinsic.yaml new file mode 100644 index 0000000000..55fcfdec87 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/simple_table_ref_parameter_intrinsic.yaml @@ -0,0 +1,22 @@ +Parameters: + ReadCapacity: + Type: Number + Default: 15 + WriteCapacity: + Type: Number + Default: 15 + EnableSSE: + Type: String # Boolean parameter types not allowed + Default: True +Resources: + MinimalTableRefParamLongForm: + Type: 'AWS::Serverless::SimpleTable' + Properties: + ProvisionedThroughput: + ReadCapacityUnits: + Ref: ReadCapacity + WriteCapacityUnits: + Ref: WriteCapacity + SSESpecification: + SSEEnabled: + Ref: EnableSSE \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/simple_table_with_extra_tags.yaml b/tests/functional/commands/validate/lib/models/simple_table_with_extra_tags.yaml new file mode 100644 index 0000000000..d8daa60c04 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/simple_table_with_extra_tags.yaml @@ -0,0 +1,15 @@ +Parameters: + TagValueParam: + Type: String + Default: value + +Resources: + MinimalTableWithTags: + Type: 'AWS::Serverless::SimpleTable' + Properties: + Tags: + TagKey1: TagValue1 + TagKey2: "" + TagKey3: + Ref: TagValueParam + TagKey4: "123" diff --git a/tests/functional/commands/validate/lib/models/simple_table_with_table_name.yaml b/tests/functional/commands/validate/lib/models/simple_table_with_table_name.yaml new file mode 100644 index 0000000000..8055c0d709 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/simple_table_with_table_name.yaml @@ -0,0 +1,22 @@ +Parameters: + MySimpleTableParameter: + Type: String + Default: TableName + +Resources: + MinimalTableWithTableName: + Type: 'AWS::Serverless::SimpleTable' + Properties: + TableName: MySimpleTable + + MinimalTableWithRefTableName: + Type: 'AWS::Serverless::SimpleTable' + Properties: + TableName: + Ref: MySimpleTableParameter + + MinimalTableWithSubTableName: + Type: 'AWS::Serverless::SimpleTable' + Properties: + TableName: + Fn::Sub: "${AWS::StackName}MySimpleTable" \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/simpletable.yaml b/tests/functional/commands/validate/lib/models/simpletable.yaml new file mode 100644 index 0000000000..cfa0b39139 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/simpletable.yaml @@ -0,0 +1,12 @@ +Resources: + MinimalTable: + Type: 'AWS::Serverless::SimpleTable' + CompleteTable: + Type: 'AWS::Serverless::SimpleTable' + Properties: + PrimaryKey: + Name: member-number + Type: Number + ProvisionedThroughput: + ReadCapacityUnits: 20 + WriteCapacityUnits: 10 diff --git a/tests/functional/commands/validate/lib/models/simpletable_with_sse.yaml b/tests/functional/commands/validate/lib/models/simpletable_with_sse.yaml new file mode 100644 index 0000000000..b9c6560e85 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/simpletable_with_sse.yaml @@ -0,0 +1,6 @@ +Resources: + TableWithSSE: + Type: 'AWS::Serverless::SimpleTable' + Properties: + SSESpecification: + SSEEnabled: true \ No newline at end of file diff --git a/tests/functional/commands/validate/lib/models/sns.yaml b/tests/functional/commands/validate/lib/models/sns.yaml new file mode 100644 index 0000000000..95e05f6f3a --- /dev/null +++ b/tests/functional/commands/validate/lib/models/sns.yaml @@ -0,0 +1,16 @@ +Resources: + SaveNotificationFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/notifications.zip + Handler: index.save_notification + Runtime: nodejs4.3 + Events: + NotificationTopic: + Type: SNS + Properties: + Topic: + Ref: Notifications + + Notifications: + Type: AWS::SNS::Topic diff --git a/tests/functional/commands/validate/lib/models/sns_existing_other_subscription.yaml b/tests/functional/commands/validate/lib/models/sns_existing_other_subscription.yaml new file mode 100644 index 0000000000..a60462de92 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/sns_existing_other_subscription.yaml @@ -0,0 +1,20 @@ +Resources: + SaveNotificationFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/notifications.zip + Handler: index.save_notification + Runtime: nodejs4.3 + Events: + NotificationTopic: + Type: SNS + Properties: + Topic: + Ref: Notifications + + Notifications: + Type: AWS::SNS::Topic + Properties: + Subscription: + - Endpoint: my-queue-arn + Protocol: sqs diff --git a/tests/functional/commands/validate/lib/models/sns_topic_outside_template.yaml b/tests/functional/commands/validate/lib/models/sns_topic_outside_template.yaml new file mode 100644 index 0000000000..0de6c218ac --- /dev/null +++ b/tests/functional/commands/validate/lib/models/sns_topic_outside_template.yaml @@ -0,0 +1,16 @@ +Parameters: + SNSTopicArn: + Type: String +Resources: + SaveNotificationFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/notifications.zip + Handler: index.save_notification + Runtime: nodejs4.3 + Events: + NotificationTopic: + Type: SNS + Properties: + Topic: + Ref: SNSTopicArn diff --git a/tests/functional/commands/validate/lib/models/sqs.yaml b/tests/functional/commands/validate/lib/models/sqs.yaml new file mode 100644 index 0000000000..9d45de0a86 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/sqs.yaml @@ -0,0 +1,14 @@ +Resources: + SQSFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/queues.zip + Handler: queue.sqs_handler + Runtime: python2.7 + Events: + MySqsQueue: + Type: SQS + Properties: + Queue: arn:aws:sqs:us-west-2:012345678901:my-queue + BatchSize: 10 + Enabled: false diff --git a/tests/functional/commands/validate/lib/models/streams.yaml b/tests/functional/commands/validate/lib/models/streams.yaml new file mode 100644 index 0000000000..ff2b54da2c --- /dev/null +++ b/tests/functional/commands/validate/lib/models/streams.yaml @@ -0,0 +1,28 @@ +Resources: + KinesisFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/streams.zip + Handler: stream.kinesis_handler + Runtime: python2.7 + Events: + MyKinesisStream: + Type: Kinesis + Properties: + Stream: arn:aws:kinesis:us-west-2:012345678901:stream/my-stream + BatchSize: 100 + StartingPosition: TRIM_HORIZON + Enabled: false + DynamoDBFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/streams.zip + Handler: stream.ddb_handler + Runtime: python2.7 + Events: + MyDDBStream: + Type: DynamoDB + Properties: + Stream: arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291 + BatchSize: 200 + StartingPosition: LATEST diff --git a/tests/functional/commands/validate/lib/models/unsupported_resources.yaml b/tests/functional/commands/validate/lib/models/unsupported_resources.yaml new file mode 100644 index 0000000000..1a74058642 --- /dev/null +++ b/tests/functional/commands/validate/lib/models/unsupported_resources.yaml @@ -0,0 +1,14 @@ +Resources: + # These resources are NOT errors from the eye of translator. + # Translator will simply ignore resources with unknown type in order to accept non-SAM resources + # in SAM template + ResourceMissingTypeShouldBeAccepted: + Properties: + StageName: Prod + DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json + + InvalidResourceTypeShouldBeAccepted: + Type: AWS::Serverless::ABCD + Properties: + StageName: Prod + DefinitionUri: s3://sam-demo-bucket/webpage_swagger.json diff --git a/tests/functional/commands/validate/lib/test_sam_template_validator.py b/tests/functional/commands/validate/lib/test_sam_template_validator.py index 0c21cb4821..fb8b42f284 100644 --- a/tests/functional/commands/validate/lib/test_sam_template_validator.py +++ b/tests/functional/commands/validate/lib/test_sam_template_validator.py @@ -1,5 +1,8 @@ from unittest import TestCase from mock import Mock +from parameterized import parameterized + +import samcli.yamlhelper as yamlhelper from samcli.commands.validate.lib.sam_template_validator import SamTemplateValidator from samcli.commands.validate.lib.exceptions import InvalidSamDocumentException @@ -7,6 +10,122 @@ class TestValidate(TestCase): + VALID_TEST_TEMPLATES = [ + ("tests/functional/commands/validate/lib/models/alexa_skill.yaml"), + ("tests/functional/commands/validate/lib/models/alexa_skill_with_skill_id.yaml"), + ("tests/functional/commands/validate/lib/models/all_policy_templates.yaml"), + ("tests/functional/commands/validate/lib/models/api_cache.yaml"), + ("tests/functional/commands/validate/lib/models/api_endpoint_configuration.yaml"), + ("tests/functional/commands/validate/lib/models/api_request_model.yaml"), + ("tests/functional/commands/validate/lib/models/api_request_model_openapi_3.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_access_log_setting.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_all_maximum.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_all_maximum_openapi_3.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_all_minimum.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_all_minimum_openapi.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_and_conditions_all_max.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_auth_no_default.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_aws_iam_auth_overrides.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_binary_media_types.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_binary_media_types_definition_body.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_canary_setting.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_auth_no_preflight_auth.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_auth_preflight_auth.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_conditions_no_definitionbody.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_only_credentials_false.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_only_headers.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_only_maxage.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_only_methods.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_and_only_origins.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_no_definitionbody.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_cors_openapi_3.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_default_aws_iam_auth.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses_all.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses_all_openapi_3.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses_implicit.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses_minimal.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_gateway_responses_string_status_code.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_method_aws_iam_auth.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_method_settings.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_minimum_compression_size.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_open_api_version.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_open_api_version_2.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_openapi_definition_body_no_flag.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_resource_refs.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_swagger_and_openapi_with_auth.yaml"), + ("tests/functional/commands/validate/lib/models/api_with_xray_tracing.yaml"), + ("tests/functional/commands/validate/lib/models/basic_function_with_tags.yaml"), + ("tests/functional/commands/validate/lib/models/basic_layer.yaml"), + ("tests/functional/commands/validate/lib/models/cloudwatch_logs_with_ref.yaml"), + ("tests/functional/commands/validate/lib/models/cloudwatchevent.yaml"), + ("tests/functional/commands/validate/lib/models/cloudwatchlog.yaml"), + ("tests/functional/commands/validate/lib/models/depends_on.yaml"), + ("tests/functional/commands/validate/lib/models/explicit_api.yaml"), + ("tests/functional/commands/validate/lib/models/explicit_api_openapi_3.yaml"), + ("tests/functional/commands/validate/lib/models/explicit_api_with_invalid_events_config.yaml"), + ("tests/functional/commands/validate/lib/models/function_concurrency.yaml"), + ("tests/functional/commands/validate/lib/models/function_event_conditions.yaml"), + ("tests/functional/commands/validate/lib/models/function_managed_inline_policy.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_alias.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_alias_and_event_sources.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_alias_intrinsics.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_condition.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_custom_codedeploy_deployment_preference.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_custom_conditional_codedeploy_deployment_preference.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_deployment_and_custom_role.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_deployment_no_service_role.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_deployment_preference.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_deployment_preference_all_parameters.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_deployment_preference_multiple_combinations.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_disabled_deployment_preference.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_dlq.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_global_layers.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_kmskeyarn.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_layers.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_many_layers.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_permissions_boundary.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_policy_templates.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_resource_refs.yaml"), + ("tests/functional/commands/validate/lib/models/function_with_sns_event_source_all_parameters.yaml"), + ("tests/functional/commands/validate/lib/models/global_handle_path_level_parameter.yaml"), + ("tests/functional/commands/validate/lib/models/globals_for_api.yaml"), + ("tests/functional/commands/validate/lib/models/globals_for_function.yaml"), + ("tests/functional/commands/validate/lib/models/globals_for_function_path.yaml"), + ("tests/functional/commands/validate/lib/models/globals_for_simpletable.yaml"), + ("tests/functional/commands/validate/lib/models/implicit_and_explicit_api_with_conditions.yaml"), + ("tests/functional/commands/validate/lib/models/implicit_api.yaml"), + ("tests/functional/commands/validate/lib/models/implicit_api_with_auth_and_conditions_max.yaml"), + ("tests/functional/commands/validate/lib/models/implicit_api_with_many_conditions.yaml"), + ("tests/functional/commands/validate/lib/models/implicit_api_with_serverless_rest_api_resource.yaml"), + ("tests/functional/commands/validate/lib/models/intrinsic_functions.yaml"), + ("tests/functional/commands/validate/lib/models/iot_rule.yaml"), + ("tests/functional/commands/validate/lib/models/layers_all_properties.yaml"), + ("tests/functional/commands/validate/lib/models/layers_with_intrinsics.yaml"), + ("tests/functional/commands/validate/lib/models/no_implicit_api_with_serverless_rest_api_resource.yaml"), + ("tests/functional/commands/validate/lib/models/s3.yaml"), + ("tests/functional/commands/validate/lib/models/s3_create_remove.yaml"), + ("tests/functional/commands/validate/lib/models/s3_existing_lambda_notification_configuration.yaml"), + ("tests/functional/commands/validate/lib/models/s3_existing_other_notification_configuration.yaml"), + ("tests/functional/commands/validate/lib/models/s3_filter.yaml"), + ("tests/functional/commands/validate/lib/models/s3_multiple_events_same_bucket.yaml"), + ("tests/functional/commands/validate/lib/models/s3_multiple_functions.yaml"), + ("tests/functional/commands/validate/lib/models/s3_with_condition.yaml"), + ("tests/functional/commands/validate/lib/models/s3_with_dependsOn.yaml"), + ("tests/functional/commands/validate/lib/models/simple_table_ref_parameter_intrinsic.yaml"), + ("tests/functional/commands/validate/lib/models/simple_table_with_extra_tags.yaml"), + ("tests/functional/commands/validate/lib/models/simple_table_with_table_name.yaml"), + ("tests/functional/commands/validate/lib/models/simpletable.yaml"), + ("tests/functional/commands/validate/lib/models/simpletable_with_sse.yaml"), + ("tests/functional/commands/validate/lib/models/sns.yaml"), + ("tests/functional/commands/validate/lib/models/sns_existing_other_subscription.yaml"), + ("tests/functional/commands/validate/lib/models/sns_topic_outside_template.yaml"), + ("tests/functional/commands/validate/lib/models/sqs.yaml"), + ("tests/functional/commands/validate/lib/models/streams.yaml"), + ("tests/functional/commands/validate/lib/models/unsupported_resources.yaml") + ] + def test_valid_template(self): template = { "AWSTemplateFormatVersion": "2010-09-09", @@ -191,4 +310,17 @@ def test_valid_template_with_s3_object_passed(self): # validate the CodeUri was not changed self.assertEquals(validator.sam_template.get("Resources").get("ServerlessApi").get("Properties").get("DefinitionUri"), {"Bucket": "mybucket-name", "Key": "swagger", "Version": 121212}) - self.assertEquals(validator.sam_template.get("Resources").get("ServerlessFunction").get("Properties").get("CodeUri"), {"Bucket": "mybucket-name", "Key": "code.zip", "Version": 121212}) \ No newline at end of file + self.assertEquals(validator.sam_template.get("Resources").get("ServerlessFunction").get("Properties").get("CodeUri"), {"Bucket": "mybucket-name", "Key": "code.zip", "Version": 121212}) + + @parameterized.expand(VALID_TEST_TEMPLATES) + def test_valid_api_request_model_template(self, template_path): + with open(template_path) as f: + template = yamlhelper.yaml_parse(f.read()) + managed_policy_mock = Mock() + managed_policy_mock.load.return_value = {"PolicyName": "FakePolicy"} + + validator = SamTemplateValidator(template, managed_policy_mock) + + # Should not throw an exception + validator.is_valid() + diff --git a/tests/unit/commands/validate/lib/test_sam_template_validator.py b/tests/unit/commands/validate/lib/test_sam_template_validator.py index 66bd659309..b8a485b743 100644 --- a/tests/unit/commands/validate/lib/test_sam_template_validator.py +++ b/tests/unit/commands/validate/lib/test_sam_template_validator.py @@ -174,8 +174,6 @@ def test_replace_local_codeuri_when_no_codeuri_given(self): # check template tempalte_resources = validator.sam_template.get("Resources") - self.assertEquals(tempalte_resources.get("ServerlessApi").get("Properties").get("DefinitionUri"), - "s3://bucket/value") self.assertEquals(tempalte_resources.get("ServerlessFunction").get("Properties").get("CodeUri"), "s3://bucket/value") From ff849ea0bce44146fb1ffa128bb6a463e94b585c Mon Sep 17 00:00:00 2001 From: Alex Wood Date: Fri, 9 Aug 2019 14:35:25 -0700 Subject: [PATCH 3/3] Get Rid of Unneeded Print Statement Used it for test debugging, not needed for launch. --- samcli/commands/validate/lib/sam_template_validator.py | 1 - 1 file changed, 1 deletion(-) diff --git a/samcli/commands/validate/lib/sam_template_validator.py b/samcli/commands/validate/lib/sam_template_validator.py index a5b529b81d..0c81c52e50 100644 --- a/samcli/commands/validate/lib/sam_template_validator.py +++ b/samcli/commands/validate/lib/sam_template_validator.py @@ -63,7 +63,6 @@ def is_valid(self): template = sam_translator.translate(sam_template=self.sam_template, parameter_values={}) LOG.debug("Translated template is:\n%s", yaml_dump(template)) - print("Translated template is:\n%s", yaml_dump(template)) except InvalidDocumentException as e: raise InvalidSamDocumentException( functools.reduce(lambda message, error: message + ' ' + str(error), e.causes, str(e)))