From bfa40b1ce7cfd3494ce66e35b369d43061c12fdd Mon Sep 17 00:00:00 2001 From: Sam Goodwin Date: Tue, 5 Feb 2019 15:23:39 -0800 Subject: [PATCH] feat(serverless): add AWS::Serverless::Application to CFN spec (#1634) Update SAM specification from goformation and patch minor bugs in it. Brings in `AWS::Serverless::Application` and updates `AWS::Serverless::Api` with authorizers. --- .../aws-serverless/test/test.serverless.ts | 45 +++- packages/@aws-cdk/cfnspec/CHANGELOG.md | 31 +++ .../cfnspec/spec-source/000_sam.spec.json | 234 ++++++++++++++++++ ...0_SAM_Serverless_Api_Authorizer_patch.json | 20 ++ ...Serverless_Application_Location_patch.json | 20 ++ .../spec-source/600_RefKinds_patch.json | 24 ++ packages/aws-cdk/lib/api/deploy-stack.ts | 2 +- 7 files changed, 369 insertions(+), 7 deletions(-) create mode 100644 packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Api_Authorizer_patch.json create mode 100644 packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Application_Location_patch.json diff --git a/packages/@aws-cdk/aws-serverless/test/test.serverless.ts b/packages/@aws-cdk/aws-serverless/test/test.serverless.ts index 59232198316cd..f2e05ce777dfc 100644 --- a/packages/@aws-cdk/aws-serverless/test/test.serverless.ts +++ b/packages/@aws-cdk/aws-serverless/test/test.serverless.ts @@ -1,9 +1,42 @@ -import { Test, testCase } from 'nodeunit'; -import {} from '../lib'; +import {expect} from '@aws-cdk/assert'; +import cdk = require('@aws-cdk/cdk'); +import { Test } from 'nodeunit'; +import { CfnApplication } from '../lib'; + +export = { + 'construct an AWS::Serverless::Application'(test: Test) { + const stack = new cdk.Stack(); + + new CfnApplication(stack, 'App', { + location: { + applicationId: 'arn:aws:serverlessrepo:us-east-1:077246666028:applications/aws-serverless-twitter-event-source', + semanticVersion: '2.0.0' + }, + parameters: { + SearchText: '#serverless -filter:nativeretweets', + TweetProcessorFunctionName: 'test' + } + }); + + expect(stack).toMatch({ + Transform: 'AWS::Serverless-2016-10-31', + Resources: { + App: { + Type: 'AWS::Serverless::Application', + Properties: { + Location: { + ApplicationId: 'arn:aws:serverlessrepo:us-east-1:077246666028:applications/aws-serverless-twitter-event-source', + SemanticVersion: '2.0.0' + }, + Parameters: { + SearchText: '#serverless -filter:nativeretweets', + TweetProcessorFunctionName: 'test' + } + } + } + } + }); -export = testCase({ - notTested(test: Test) { - test.ok(true, 'No tests are specified for this package.'); test.done(); } -}); +}; diff --git a/packages/@aws-cdk/cfnspec/CHANGELOG.md b/packages/@aws-cdk/cfnspec/CHANGELOG.md index 5a87d5be5a265..2f4d8d04edff8 100644 --- a/packages/@aws-cdk/cfnspec/CHANGELOG.md +++ b/packages/@aws-cdk/cfnspec/CHANGELOG.md @@ -1,3 +1,34 @@ +# Serverless Application Model (SAM) Resource Specification v2016-10-31 + +## New Resource Types + +* AWS::Serverless::Application +* AWS::Serverless::LayerVersion + +## Attribute Changes + + +## Property Changes + +* AWS::Serverless::Api Auth (__added__) +* AWS::Serverless::Api BinaryMediaTypes (__added__) +* AWS::Serverless::Api Cors (__added__) +* AWS::Serverless::Api EndpointConfiguration (__added__) +* AWS::Serverless::Function AutoPublishAlias (__added__) +* AWS::Serverless::Function DeploymentPreference (__added__) +* AWS::Serverless::Function Layers (__added__) +* AWS::Serverless::Function ReservedConcurrentExecutions (__added__) +* AWS::Serverless::SimpleTable SSESpecification (__added__) +* AWS::Serverless::SimpleTable TableName (__added__) +* AWS::Serverless::SimpleTable Tags (__added__) + +## Property Type Changes + +* AWS::Serverless::Api.Auth (__added__) +* AWS::Serverless::Function.DeploymentPreference (__added__) +* AWS::Serverless::SimpleTable.SSESpecification (__added__) + + # CloudFormation Resource Specification v2.21.0 diff --git a/packages/@aws-cdk/cfnspec/spec-source/000_sam.spec.json b/packages/@aws-cdk/cfnspec/spec-source/000_sam.spec.json index 08fd45967678e..4df0fee4270b6 100644 --- a/packages/@aws-cdk/cfnspec/spec-source/000_sam.spec.json +++ b/packages/@aws-cdk/cfnspec/spec-source/000_sam.spec.json @@ -1,5 +1,22 @@ { "PropertyTypes": { + "AWS::Serverless::Api.Auth": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api-auth-object", + "Properties": { + "Authorizers": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api-auth-object", + "Required": false, + "Type": "String", + "UpdateType": "Immutable" + }, + "DefaultAuthorizer": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api-auth-object", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::Api.S3Location": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#s3-location-object", "Properties": { @@ -23,6 +40,23 @@ } } }, + "AWS::Serverless::Application.ApplicationLocation": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "Properties": { + "ApplicationId": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveType": "String", + "Required": true, + "UpdateType": "Immutable" + }, + "SemanticVersion": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveType": "String", + "Required": true, + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::Function.AlexaSkillEvent": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#alexaskill", "Properties": { @@ -98,6 +132,43 @@ } } }, + "AWS::Serverless::Function.DeploymentPreference": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "Properties": { + "Alarms": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "PrimitiveItemType": "String", + "Required": false, + "Type": "List", + "UpdateType": "Immutable" + }, + "Enabled": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "PrimitiveType": "Boolean", + "Required": false, + "UpdateType": "Immutable" + }, + "Hooks": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "PrimitiveItemType": "String", + "Required": false, + "Type": "Map", + "UpdateType": "Immutable" + }, + "Role": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "Type": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#deploymentpreference-object", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::Function.DynamoDBEvent": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#dynamodb", "Properties": { @@ -370,6 +441,17 @@ "UpdateType": "Immutable" } } + }, + "AWS::Serverless::SimpleTable.SSESpecification": { + "Documentation": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html", + "Properties": { + "SSEEnabled": { + "Documentation": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html", + "PrimitiveType": "Boolean", + "Required": false, + "UpdateType": "Immutable" + } + } } }, "ResourceSpecificationTransform": "AWS::Serverless-2016-10-31", @@ -378,6 +460,19 @@ "AWS::Serverless::Api": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", "Properties": { + "Auth": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", + "Required": false, + "Type": "Auth", + "UpdateType": "Immutable" + }, + "BinaryMediaTypes": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", + "PrimitiveItemType": "String", + "Required": false, + "Type": "List", + "UpdateType": "Immutable" + }, "CacheClusterEnabled": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", "PrimitiveType": "Boolean", @@ -390,6 +485,12 @@ "Required": false, "UpdateType": "Immutable" }, + "Cors": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, "DefinitionBody": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", "PrimitiveType": "Json", @@ -407,6 +508,12 @@ ], "UpdateType": "Immutable" }, + "EndpointConfiguration": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, "MethodSettings": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi", "PrimitiveType": "Json", @@ -434,9 +541,56 @@ } } }, + "AWS::Serverless::Application": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "Properties": { + "Location": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveType": "String", + "Required": true, + "Types": [ + "ApplicationLocation" + ], + "UpdateType": "Immutable" + }, + "NotificationArns": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveItemType": "String", + "Required": false, + "Type": "List", + "UpdateType": "Immutable" + }, + "Parameters": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveItemType": "String", + "Required": false, + "Type": "Map", + "UpdateType": "Immutable" + }, + "Tags": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveItemType": "String", + "Required": false, + "Type": "Map", + "UpdateType": "Immutable" + }, + "TimeoutInMinutes": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapplication", + "PrimitiveType": "Integer", + "Required": false, + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::Function": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", "Properties": { + "AutoPublishAlias": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, "CodeUri": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", "PrimitiveTypes": [ @@ -454,6 +608,12 @@ "Type": "DeadLetterQueue", "UpdateType": "Immutable" }, + "DeploymentPreference": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", + "Required": false, + "Type": "DeploymentPreference", + "UpdateType": "Immutable" + }, "Description": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", "PrimitiveType": "String", @@ -491,6 +651,13 @@ "Required": false, "UpdateType": "Immutable" }, + "Layers": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", + "PrimitiveItemType": "String", + "Required": false, + "Type": "List", + "UpdateType": "Immutable" + }, "MemorySize": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", "PrimitiveType": "Integer", @@ -514,6 +681,12 @@ ], "UpdateType": "Immutable" }, + "ReservedConcurrentExecutions": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", + "PrimitiveType": "Integer", + "Required": false, + "UpdateType": "Immutable" + }, "Role": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction", "PrimitiveType": "String", @@ -553,6 +726,48 @@ } } }, + "AWS::Serverless::LayerVersion": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "Properties": { + "CompatibleRuntimes": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveItemType": "String", + "Required": false, + "Type": "List", + "UpdateType": "Immutable" + }, + "ContentUri": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "Description": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "LayerName": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "LicenseInfo": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "RetentionPolicy": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesslayerversion", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + } + } + }, "AWS::Serverless::SimpleTable": { "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable", "Properties": { @@ -567,6 +782,25 @@ "Required": false, "Type": "ProvisionedThroughput", "UpdateType": "Immutable" + }, + "SSESpecification": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable", + "Required": false, + "Type": "SSESpecification", + "UpdateType": "Immutable" + }, + "TableName": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable", + "PrimitiveType": "String", + "Required": false, + "UpdateType": "Immutable" + }, + "Tags": { + "Documentation": "https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable", + "PrimitiveItemType": "String", + "Required": false, + "Type": "Map", + "UpdateType": "Immutable" } } } diff --git a/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Api_Authorizer_patch.json b/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Api_Authorizer_patch.json new file mode 100644 index 0000000000000..0f8939da4e86c --- /dev/null +++ b/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Api_Authorizer_patch.json @@ -0,0 +1,20 @@ +{ + "PropertyTypes": { + "AWS::Serverless::Api.Auth": { + "patch": { + "description": "Sets AWS::Serverless::Api.Auth#Authorizers to Json", + "operations": [ + { + "op": "add", + "path": "/Properties/Authorizers/PrimitiveType", + "value": "Json" + }, + { + "op": "remove", + "path": "/Properties/Authorizers/Type" + } + ] + } + } + } +} diff --git a/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Application_Location_patch.json b/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Application_Location_patch.json new file mode 100644 index 0000000000000..6a1a62460044e --- /dev/null +++ b/packages/@aws-cdk/cfnspec/spec-source/500_SAM_Serverless_Application_Location_patch.json @@ -0,0 +1,20 @@ +{ + "ResourceTypes": { + "AWS::Serverless::Application": { + "patch": { + "description": "Renames PrimitiveType in AWS::Serverless::Application#Location to PrimitiveTypes", + "operations": [ + { + "op": "remove", + "path": "/Properties/Location/PrimitiveType" + }, + { + "op": "add", + "path": "/Properties/Location/PrimitiveTypes", + "value": [ "String" ] + } + ] + } + } + } +} diff --git a/packages/@aws-cdk/cfnspec/spec-source/600_RefKinds_patch.json b/packages/@aws-cdk/cfnspec/spec-source/600_RefKinds_patch.json index 43724f7f7e65d..56b8a7c3c136b 100644 --- a/packages/@aws-cdk/cfnspec/spec-source/600_RefKinds_patch.json +++ b/packages/@aws-cdk/cfnspec/spec-source/600_RefKinds_patch.json @@ -3504,6 +3504,18 @@ "description": "Set RefKind of AWS::SageMaker::NotebookInstanceLifecycleConfig to Arn" } }, + "AWS::Serverless::Application": { + "patch": { + "operations": [ + { + "op": "add", + "path": "/RefKind", + "value": "Name" + } + ], + "description": "Set RefKind of AWS::Serverless::Application to Name" + } + }, "AWS::Serverless::Api": { "patch": { "operations": [ @@ -3528,6 +3540,18 @@ "description": "Set RefKind of AWS::Serverless::Function to Name" } }, + "AWS::Serverless::LayerVersion": { + "patch": { + "operations": [ + { + "op": "add", + "path": "/RefKind", + "value": "Arn" + } + ], + "description": "Set RefKind of AWS::Serverless::LayerVersion to Arn" + } + }, "AWS::Serverless::SimpleTable": { "patch": { "operations": [ diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 55a83d754400d..8d592b1948739 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -71,7 +71,7 @@ export async function deployStack(options: DeployStackOptions): Promise