Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DEVELOPMENT_GUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Install snakeviz `pip install snakeviz`

.. code-block:: shell

python -m cProfile -o sam_profile_results bin/sam-translate.py translate --input-file=tests/translator/input/alexa_skill.yaml --output-file=cfn-template.json
python -m cProfile -o sam_profile_results bin/sam-translate.py translate --template-file=tests/translator/input/alexa_skill.yaml --output-template=cfn-template.json
snakeviz sam_profile_results

Verifying transforms
Expand All @@ -96,7 +96,7 @@ If you make changes to the transformer and want to verify the resulting CloudFor

# Transform your SAM template into a CloudFormation template
# Replace "output-template.yaml" if you didn't run the package command above or specified a different path for --output-template-file
bin/sam-translate.py --input-file=output-template.yaml
bin/sam-translate.py --template-file=output-template.yaml

# Deploy your transformed CloudFormation template
# Replace MY_STACK_NAME with a unique name each time you deploy
Expand Down
3 changes: 2 additions & 1 deletion docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Currently, the following resources and properties are being supported:
Api:
# Properties of AWS::Serverless::Api
# Also works with Implicit APIs
Auth:
Name:
DefinitionUri:
CacheClusterEnabled:
Expand All @@ -90,7 +91,7 @@ Currently, the following resources and properties are being supported:

SimpleTable:
# Properties of AWS::Serverless::SimpleTable
SSESpecification
SSESpecification:

Implicit APIs
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/internals/generated_resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CloudFormation Resources Generated By SAM
:local:
:backlinks: none

When you create a Serverless Function or a Serverlesss API, SAM will create additional AWS resources wire everything up.
When you create a Serverless Function or a Serverlesss API, SAM will create additional AWS resources to wire everything up.
For example, when you create a ``AWS::Serverless::Function``, SAM will create a Lambda Function resource
along with an IAM Role resource to give appropriate permissions for your function. This document describes all
such generated resources, how they are named, and how to refer to them in your SAM template.
Expand Down
2 changes: 1 addition & 1 deletion docs/website/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CommonMark==0.5.4
docutils==0.14
idna==2.6
imagesize==0.7.1
Jinja2==2.10
Jinja2>=2.10.1
MarkupSafe==1.0
Pygments==2.2.0
pytz==2017.3
Expand Down
61 changes: 29 additions & 32 deletions examples/2016-10-31/lambda_safe_deployments/src/preTrafficHook.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
// @ts-check
'use strict';

const aws = require('aws-sdk');
const codedeploy = new aws.CodeDeploy({apiVersion: '2014-10-06'});

exports.handler = (event, context, callback) => {
exports.handler = async (event, context, callback) => {

console.log("Entering PreTraffic Hook!");
console.log(JSON.stringify(event));
//Read the DeploymentId from the event payload.
var deploymentId = event.DeploymentId;
console.log(deploymentId);
console.log("Entering PreTraffic Hook!");
console.log(JSON.stringify(event));

//Read the DeploymentId from the event payload.
let deploymentId = event.DeploymentId;
console.log("deploymentId=" + deploymentId);

//Read the LifecycleEventHookExecutionId from the event payload
var lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
console.log(lifecycleEventHookExecutionId);

/*
[Perform validation or prewarming steps here]
*/
// Prepare the validation test results with the deploymentId and
let lifecycleEventHookExecutionId = event.LifecycleEventHookExecutionId;
console.log("lifecycleEventHookExecutionId=" + lifecycleEventHookExecutionId);

/*
[Perform validation or prewarming steps here]
*/

// Prepare the validation test results with the deploymentId and
// the lifecycleEventHookExecutionId for AWS CodeDeploy.
var params = {
let params = {
deploymentId: deploymentId,
lifecycleEventHookExecutionId: lifecycleEventHookExecutionId,
status: 'Succeeded' // status can be 'Succeeded' or 'Failed'
};

// Pass AWS CodeDeploy the prepared validation test results.
codedeploy.putLifecycleEventHookExecutionStatus(params, function(err, data) {
if (err) {
// Validation failed.
console.log('Validation test failed');
console.log(err);
console.log(data);
callback('Validation test failed');
} else {
// Validation succeeded.
console.log('Validation test succeeded');
callback(null, 'Validation test succeeded');
}
});

try {
await codedeploy.putLifecycleEventHookExecutionStatus(params).promise();
console.log("putLifecycleEventHookExecutionStatus done. executionStatus=[" + params.status + "]");
return 'Validation test succeeded'
}
catch (err) {
console.log("putLifecycleEventHookExecutionStatus ERROR: " + err);
throw new Error('Validation test failed')
}

}

// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function
// See more: https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html#reference-appspec-file-structure-hooks-section-structure-lambda-sample-function
5 changes: 3 additions & 2 deletions examples/2016-10-31/lambda_safe_deployments/src/safeTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';


exports.handler = (event, context, callback) => {
exports.handler = async (event, context, callback) => {

console.log("Function loaded! " + context.functionName + ":" + context.functionVersion);

callback(null, "Success");
}
}
6 changes: 3 additions & 3 deletions examples/2016-10-31/lambda_safe_deployments/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Resources:
Properties:
Handler: safeTest.handler
CodeUri: src/
Runtime: nodejs6.10
Runtime: nodejs8.10
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery1Minute
Expand All @@ -35,10 +35,10 @@ Resources:
Action:
- "lambda:InvokeFunction"
Resource: !Ref safeTest.Version
Runtime: nodejs6.10
Runtime: nodejs8.10
FunctionName: 'CodeDeployHook_preTrafficHook'
DeploymentPreference:
Enabled: false
Environment:
Variables:
CurrentVersion: !Ref safeTest.Version
CurrentVersion: !Ref safeTest.Version
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,6 @@ Resources:

- FilterLogEventsPolicy:
LogGroupName: name

- StepFunctionsExecutionPolicy:
StateMachineName: name
2 changes: 1 addition & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
boto3~=1.5
enum34~=1.1; python_version<"3.4"
jsonschema~=2.6
jsonschema~=3.0
six~=1.11

2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.11.0'
__version__ = '1.12.0'
2 changes: 1 addition & 1 deletion samtranslator/model/sam_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _event_resources_to_link(self, resources):
try:
event_source = self.event_resolver.resolve_resource_type(event_dict).from_dict(
self.logical_id + logical_id, event_dict, logical_id)
except TypeError as e:
except (TypeError, AttributeError) as e:
raise InvalidEventException(logical_id, "{}".format(e))
event_resources[logical_id] = event_source.resources_to_link(resources)
return event_resources
Expand Down
28 changes: 28 additions & 0 deletions samtranslator/policy_templates_data/policy_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,34 @@
}
]
}
},
"StepFunctionsExecutionPolicy": {
"Description": "Gives permission to start a Step Functions state machine execution",
"Parameters": {
"StateMachineName": {
"Description":"The name of the state machine to execute."
}
},
"Definition": {
"Statement": [
{
"Effect": "Allow",
"Action": [
"states:StartExecution"
],
"Resource": {
"Fn::Sub": [
"arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}",
{
"stateMachineName": {
"Ref": "StateMachineName"
}
}
]
}
}
]
}
}
}
}
12 changes: 11 additions & 1 deletion samtranslator/sdk/resource.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from enum import Enum
from samtranslator.model.exceptions import InvalidDocumentException, InvalidTemplateException
from samtranslator.model.types import is_str


class SamResource(object):
Expand Down Expand Up @@ -30,7 +32,15 @@ def valid(self):

:return: True, if the resource is valid
"""
# As long as the type is valid.
# As long as the type is valid and type string.
# validate the condition should be string

if self.condition:

if not is_str()(self.condition, should_raise=False):
raise InvalidDocumentException([
InvalidTemplateException("Every Condition member must be a string.")])

return SamResourceType.has_value(self.type)

def to_dict(self):
Expand Down
4 changes: 4 additions & 0 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,11 @@ def set_path_default_authorizer(self, path, default_authorizer, authorizers):
authorizers param.
:param list authorizers: List of Authorizer configurations defined on the related Api.
"""

for method_name, method in self.get_path(path).items():
# Excluding paramters section
if method_name == "parameters":
continue
self.set_method_authorizer(path, method_name, default_authorizer, authorizers,
default_authorizer=default_authorizer, is_default=True)

Expand Down
3 changes: 3 additions & 0 deletions tests/translator/input/all_policy_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ Resources:

- SSMParameterReadPolicy:
ParameterName: name

- StepFunctionsExecutionPolicy:
StateMachineName: name
10 changes: 10 additions & 0 deletions tests/translator/input/error_function_invalid_event_type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ Resources:
Method: get
Path: /

TestFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: code/
Handler: lambda_handler.handler

Runtime: python3.6
Events:
FileUploaded:

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Conditions:
MyCondition:
Fn::Equals:
- true
- false

Resources:
ConditionFunction:
Type: 'AWS::Serverless::Function'
Condition:
Ref: MyCondition
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python2.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Resources:
helloworld:
Type: AWS::Serverless::Application
Properties:
Location:
ApplicationId: arn:aws:serverlessrepo:us-east-1:077246666028:applications/hello-world
SemanticVersion:
64 changes: 64 additions & 0 deletions tests/translator/input/global_handle_path_level_parameter.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading